我想为我的阅读器应用程序制作一个自定义方向锁定按钮,我认为鞭打它不会太糟糕,但可惜我是那个被鞭打的人。
首先,我确实有这种方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
然后我在想我可以用这样的动作方法处理实际的锁定:
- (IBAction) screenLock:(id)sender{
if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait){
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}else{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
}
但是,唉,这段代码不会影响指示视图旋转的前者......
我对这一切都错了吗?有什么更好的方法呢?我只想有一个本地的、简单的方法让我的用户锁定他们的屏幕方向。我想这将使用一个布尔值,他们点击一个按钮锁定,然后再次点击解锁......
想法?谢谢!!