【发布时间】:2014-08-05 14:29:23
【问题描述】:
在通过 stackoverflow 浏览答案后,我决定提出一个问题。
据我了解,我应该重写supportedInterfaceOrientation 来处理方向。例如,为了我这样实现它
- (NSUInteger)supportedInterfaceOrientations {
if (self.forceLandscape) {
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
这让控制器在出现时以横向模式启动,并在默认情况下启用 forceLandscape。然后有一个按钮可以改变按钮按下的方向
- (IBAction)buttonPress:(id)sender {
self.forceLandscape = !self.forceLandscape;
UIInterfaceOrientation o = UIInterfaceOrientationPortrait;
if (self.forceLandscape) {
o = UIInterfaceOrientationLandscape;
}
[UIApplication sharedApplication].statusBarOrientation = o;
}
按钮按下会在纵向和横向模式之间交替切换。通过设置状态栏方向,它会调用supportedInterfaceOrientations 来改变我的方向。它确实调用该方法并在第一次按下按钮时返回蒙版肖像,但它不会改变我的方向。这是我要解决的问题。希望有解决方法。
将状态栏方向更改替换为此代码
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: o] forKey:@"orientation"];
调用supportedInterfaceMethod,它确实改变了方向。但是它只能工作一次,并且它可以访问私有代码并且会被 Apple 拒绝,这是不可取的。
【问题讨论】:
标签: ios objective-c iphone orientation