此時我已將ViewControllerA保持爲縱向模式。爲此,我正在使用preferredInterfaceOrientationForPresentationiOS 7在解除推送時強制縱向定位
這可確保ViewControllerA在推入時處於縱向模式。但是,如果我從ViewControllerA推送到ViewControllerB,切換到ViewControllerB中的橫向模式,,然後退回到ViewControllerA,ViewControllerA可以以橫向模式呈現。我的願望是繼續ViewControllerB的多方位支持,但強制ViewControllerA自動旋轉到肖像。
此外,出於某種原因shouldAutorotate似乎不被調用ViewControllerA。也許解決這個問題可以解決整個問題?
的UINavigationController + Orientation.h類別
@interface UINavigationController (Orientation)
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end
的UINavigationController + Orientation.m類別
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
ViewControllerA.m
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
它仍然不起作用。我正在使用與您所做的相同的方向設置(除了顛倒以外)。我嘗試在viewDidLoad和viewWillAppear中都使用**((AppDelegate *)[UIApplication sharedApplication] .delegate).allowViewRotation **,但兩者都沒有阻止ViewControllerA在退回時加載爲橫向格式。 – 2014-09-10 16:50:29
確保默認值是allowViewRotation = NO。並在ViewControllerB的** viewWillAppear:**和** viewWillDisappear裏面加上YES/NO改變:**' - (void)viewWillAppear:(BOOL)animated動畫 {super viewWillAppear:animated]; appDelegate.allowViewRotation = YES; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; appDelegate.allowViewRotation = NO; }' – Mike 2014-09-10 17:43:54
嘗試調用attemptRotationToDeviceOrientation來強制應用程序調用** supportedInterfaceOrientationsForWindow ** https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/clm/UIViewController/attemptRotationToDeviceOrientation – Mike 2014-09-10 17:53:37