崩潰

2012-04-20 223 views
4

此代碼(if語句與動畫):崩潰

// works 
if (_camOrientation == UIDeviceOrientationPortrait) { 
    [UIView animateWithDuration:0.5f animations:^(void){ 
     [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))]; 
    }]; 
} else if (_camOrientation == UIDeviceOrientationLandscapeLeft) { 
    [UIView animateWithDuration:0.5f animations:^(void){ 
     [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))]; 
    }]; 
} 

這也適用(switch語句無動畫):

// works 
switch (_camOrientation) { 
    case UIDeviceOrientationPortrait: 
     [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))]; 
     break; 

    case UIDeviceOrientationLandscapeLeft: 
     [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))]; 
     break; 

    default: 
     break; 
} 

這一個崩潰(帶動畫的開關語句):

// crashes 
switch (_camOrientation) { 
    case UIDeviceOrientationPortrait: 
     [UIView animateWithDuration:0.5f animations:^(void){ 
      [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))]; 
     }]; 
     break; 

    case UIDeviceOrientationLandscapeLeft: 
     [UIView animateWithDuration:0.5f animations:^(void){ 
      [_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))]; 
     }]; 
     break; 

    default: 
     break; 
} 

爲什麼我不能在switch語句中使用動畫塊?!?

+0

給我們介紹一下崩潰的更多細節。究竟發生了什麼?哪條線路崩潰?是否引發異常或是否有其他類似的崩潰? – 2012-04-20 16:42:37

回答

6

你應該能夠:)

嘗試添加在你的情況下{ }這樣的:

case UIDeviceOrientationPortrait: { 
    [UIView animateWithDuration:0.5f animations:^void{ 
     [_distanceView setTransform:CGAffineTransformMakeRotation(0.0)]; 
    }]; 
    break; 
} 
+0

哇,謝謝......讓我覺得自己像一個白癡;-)當然,現在的作品。是否有一個生成設置會給出不使用{}的警告? – 2012-04-20 16:43:47

+0

應該有 - 當我使用ARC時偶爾會得到一個 - 像'switch statement in protected state'或類似的東西。雖然如果它編譯它不會期望這個崩潰:( – deanWombourne 2012-04-20 16:59:35

+0

嗯...我使用ARC和現在激活所有警告,但仍然沒有得到一個警告這個具體的情況。)無論如何,謝謝;) – 2012-04-20 17:26:12