您的问题源于这样一个事实:当调用willRotateToInterfaceOrientation:时,正在旋转的视图已经设置了其“方向”属性,并且处理旋转的动画块也准备在单独的线程上运行。从
the documentation
:
从用于旋转视图的动画块中调用此方法。您可以替代此方法,并使用它来配置在视图旋转期间应发生的其他动画。
我建议重写shouldAutorotateToInterfaceOrientation:方法来启动动画,然后对支持的方向返回YES:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == (UIDeviceOrientationPortrait || UIDeviceOrientationPortraitUpsideDown) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 0;
[UIView commitAnimations];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
theView.alpha = 1;
[UIView commitAnimations];
}
return YES;
}
这应该确保在设置UIViewController的方向和激发旋转动画之前动画运行。根据设备硬件速度的不同,您可能需要添加一点延迟才能获得所需的效果。