![](/img/trans.png)
[英]ios preferredInterfaceOrientationForPresentation not called
[英]preferredInterfaceOrientationForPresentation only called once in iOS7 with subclass of UINavigationController
我有這樣子類化UINavigationController:
- (BOOL)shouldAutorotate {
if (self.topViewController != nil) return [self.topViewController shouldAutorotate];
else return [super shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.topViewController != nil) return [self.topViewController supportedInterfaceOrientations];
else return [super supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if (self.topViewController != nil) return [self.topViewController preferredInterfaceOrientationForPresentation];
else return [super preferredInterfaceOrientationForPresentation];
}
在推送到堆棧中的每個視圖控制器中,對supportedInterfaceOrientations
和shouldAutorotate
的調用都很好,但是,僅在與iOS 7一起使用時, preferredInterfaceOrientationForPresentation
才被調用。任何加載每個視圖控制器時觸發preferredInterfaceOrientationForPresentation
想法都將受到贊賞=)
在此先感謝您,我的英語很抱歉=)
我會回答自己。 我對UINavigationController進行了子類化,以便在將某些視圖控制器推入堆棧之前調用問題中發布的三個方法,以將方向限制為縱向,橫向或任何我想要的方向。 問題在於視圖控制器上沒有調用preferredInterfaceOrientationForPresentation,因此,它們沒有以我想要的方向顯示。 為了強制iOS在一個方向或另一個方向上顯示視圖控制器,我在viewDidLoad中檢查方向,如果不是我想要的方向,則按如下方式推送臨時視圖控制器:
- (void)viewDidLoad {
[super viewDidLoad];
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
TempViewController *temp = [[TempViewController alloc] init];
[self.navigationController pushViewController:temp animated:YES];
}
}
然后在TempViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController popViewControllerAnimated:YES];
}
結果是顯示的第一個視圖控制器具有preferredInterfaceOrientationForPresentation中指定的方向。 也許這有點棘手,並且無法使用其他實現來完成,但至少可以做到這一點=)
嗨,這是我在做什么,您可以嘗試一下:
應該自動旋轉,supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation在iOS 7中無法正常工作
這是一個很大的頭痛。
快樂的編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.