And*_*ese 4 animation objective-c objective-c-blocks
此代码有效(if-statement with animated):
// 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))];
}];
}
Run Code Online (Sandbox Code Playgroud)
这也有效(没有动画的switch语句):
// works
switch (_camOrientation) {
case UIDeviceOrientationPortrait:
[_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(0.0))];
break;
case UIDeviceOrientationLandscapeLeft:
[_distanceView setTransform:CGAffineTransformMakeRotation(degreesToRadian(90.0))];
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
这个崩溃了(带动画的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;
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能在switch语句中使用动画块?!?
你应该能够 :)
尝试添加{ }您的案例,如下所示:
case UIDeviceOrientationPortrait: {
[UIView animateWithDuration:0.5f animations:^void{
[_distanceView setTransform:CGAffineTransformMakeRotation(0.0)];
}];
break;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |