This code works (if-statement with animations):
// 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))];
}];
}
This also works (switch-statement without animations):
// works
switch (_camOrientation) {
case UIDeviceOrientationPortrait:
[_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))];
break;
case UIDeviceOrientationLandscapeLeft:
[_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))];
break;
default:
break;
}
This one crashes (switch-statement with animation):
// 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;
}
Why can't I use animation blocks in a switch statement?!?
You should be able to :)
Try adding
{ }
around your cases like this :