[英]UIViewController handle orientation iOS 6.0 on iPad
在我的應用程序中,我需要為ViewControllers
處理不同的方向。
ViewController1
必須僅支持landascape方向。 ViewController2
必須支持橫向+縱向方向。 我在Summury項目中啟用了所有這樣的方向:
所以,我在ViewController1
插入此代碼:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
我在ViewController2
插入此代碼:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
問題是ViewController1
也是縱向旋轉(它應該只支持橫向)。
任何想法?
非常感謝你們!
你的viewController是你的rootViewController嗎? 如果沒有,那可能是你的問題。
如果你的rootViewController是一個UINavigationController,你應該知道它不會將這些消息轉發給它的topViewController。 所以,如果這是你的情況,我建議你使用UINavigationController的子類,你可以在其中覆蓋這些新方法,以便轉發到topViewController。
在iOS 6之前,這很好用
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientatio n { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) return YES;
else return NO; }
但在iOS 6中已被棄用
現在,您應指定所需的方向並選擇演示方向
你應該寫
- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; }
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
希望能幫助到你
祝好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.