此代码有效(带有动画的 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 语句中使用动画块?!?