单击按钮可锁定iPad方向

时间:2012-09-25 05:02:39

标签: iphone objective-c ios cocoa-touch ipad

在我基于iPad的应用程序中,单击按钮会初始化照片拍摄。

我背靠背拍了五张照片。一旦我触摸按钮,我需要锁定当前方向,并且应该按照这个特定方向拍摄五张照片。

说,如果目前我处于横向模式,如果我触摸按钮,则应在此横向模式下拍摄五张照片。

我目前正在使用以下代码。

它有效,但核心并不完美,有一个滞后时间。按下按钮几秒钟后,它就会被锁定。

// End notifying the orientation change
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

// Begin notifying the orientation change
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

你能为此提出任何解决方案吗?

提前致谢

1 个答案:

答案 0 :(得分:2)

覆盖了shouldAutorotate方法(我在iOS6上测试它并且它可以工作):

- (BOOL)shouldAutorotate
{
    return !self.isLocked;
}

- (IBAction)buttonClicked:(id)sender
{
    self.isLocked = !self.isLocked;
}
@end