我想允许方向根据对 View Controller 的 shouldAutorotateToInterfaceOrientation 调用进行旋转。但是,我希望它立即执行此操作并跳过旋转动画(导致整个 View 旋转时角落显示黑色旋转动画的动画。
有谁知道是否有办法指定您希望它立即发生(没有动画)?
最佳答案
为了执行您想要的操作,您必须手动旋转(并调整大小) View 。没有任何属性可以让您轻松更改以轻松执行您想要的操作。下面是注册设备旋转事件的代码。
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
//Whenever the device orientation changes, orientationChanged will be called
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
//Based upon which orientation the device is in, update your View rotations.
//A simple view.transform = CGAffineTransformMakeRotation(whatever); will work well.
}
我认为您应该完全删除 shouldAutoRotateToInterfaceOrientation: 函数。
当 View 卸载时,您还应该调用 [[UIDevice currentDevice] endGenerateDeviceOrientationNotifications];
。
关于iphone - 有没有办法从 shouldAutorotateToInterfaceOrientation 跳过旋转动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3233032/