此代码(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;
}
这一次崩溃(switch语句与动画):
// 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语句?!?