【发布时间】:2014-09-10 15:48:24
【问题描述】:
此时,我已将 ViewControllerA 保持在纵向模式中。为此,我使用 preferredInterfaceOrientationForPresentation
这可确保 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;
}
【问题讨论】:
标签: ios xcode uinavigationcontroller orientation