在我的应用程序中的某个时刻,我想暂时禁用旋转功能 - 有效地“锁定”代码中的方向,类似于锁定拨动开关在 iPad 上的硬件功能。
我目前在做:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]
当我完成后,我会调用:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]
虽然这一切似乎都有效,但 API 文档表明应该始终有一个开始,然后是一个结束 - 而我基本上是相反的。是否有更合适的 API 来处理“锁定方向”?
最佳答案
我认为这就像不响应 Controller 的方向变化一样简单。您可以根据传递的参数有条件地返回 true 或 false,您不必总是返回 true。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (rand()%2 == 0) { // evaluate if I should allow rotate
return YES;
} else {
return NO;
}
}
关于iphone - 如何暂时锁定 iPad/iPhone 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3071989/