![](/img/trans.png)
[英]shouldAutorotateToInterfaceOrientation not being called in iOS 6
[英]shouldAutorotateToInterfaceOrientation: never called
我在“部署信息”下將支持的界面方向設置為“縱向顛倒”以外的所有方向。
我想重寫shouldAutorotateToInterfaceOrientation:以獲得自定義行為。 (即根據條件支持情況)
由於限制,我只有一個viewcontroller(自定義視圖轉換)
這是我的appdelegate中的代碼如下所示:
self.viewController = [[MyController alloc]initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
在myController.m中,我重寫了shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
應用程序會自動旋轉到所有方向,但人像顛倒,並且永遠不會調用。 我在運行時嘗試了應從shouldAutorotateToInterfaceOrientation返回更改的建議,但沒有成功。 為什么?
另外,在運行時更改旋轉支持的最佳方法是什么?
更新:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
被叫。 我嘗試放入
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
沒有成功:(
正在使用ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
在ios6上已棄用
它為我工作:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
if ([self isKindOfClass:[YourViewController class]]) { // Your view class
orientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
}
return orientations;
}
方向:
orientations |= UIInterfaceOrientationMaskLandscapeLeft;
orientations |= UIInterfaceOrientationMaskLandscapeRight;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.