当我的iPhone界面旋转时,我想为UIViewController的特定UIView做淡入/淡出......就像......
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 0;
[UIView commitAnimations];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 1;
[UIView commitAnimations];
}
但动画在旋转开始之前没有完成(我们可以看到视图开始自我调整大小)......
有没有办法延迟旋转开始?
“持续时间”是旋转动画的持续时间,对吧?
2 回答
我发现当前运行循环运行的时间与前一个动画相同,确实延迟了旋转 .
你的问题源于这样一个事实:当调用willRotateToInterfaceOrientation:时,被旋转的视图已经设置了它的orientation属性,并且处理旋转的动画块也准备好在一个单独的线程上运行 . 来自the documentation:
我建议覆盖shouldAutorotateToInterfaceOrientation:方法来触发动画,然后返回YES以获得支持的方向:
这应确保在设置UIViewController的方向并触发旋转动画之前运行动画 . 您可能需要添加一点延迟才能获得所需的效果,具体取决于设备的硬件速度 .