【发布时间】:2023-04-26 10:57:01
【问题描述】:
添加: 我看到我的问题经常在没有人赞成的情况下被查看,所以我决定你们没有得到你搜索的内容。将您重定向到具有非常好的答案的问题 How to handle orientation changes in iOS6
对方向变化的具体要求: Restricted rotation
欢迎投票 :)
我从 Master Detail 模板创建了一个新项目,并尝试以横向启动它。 众所周知,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法已弃用,我们必须使用
- (NSUInteger)supportedInterfaceOrientations
和/或
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
这是我的代码:
- (NSUInteger)supportedInterfaceOrientations {
NSLog(@"supported called");
return UIInterfaceOrientationMaskAll;//Which is actually a default value
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
NSLog(@" preferred called");//This method is never called. WHY?
return UIInterfaceOrientationLandscapeRight;
}
如您所见,我正在尝试以首选方法返回横向,但它从未被调用。 p.s.文档状态:
讨论 系统在展示视图时调用该方法 控制器全屏。您在查看时实现此方法 控制器支持两个或多个方向但内容出现 在这些方向之一中表现最好。
如果你的视图控制器实现了这个方法,那么当出现时, 它的视图以首选方向显示(尽管稍后可以 旋转到另一个支持的旋转)。如果不实施 这种方法,系统使用当前的视图控制器呈现 状态栏的方向。
所以,问题是:为什么 prefferredOrientation 方法永远不会被调用?以及我们应该如何处理不同控制器中的不同方向?谢谢! PS不要将问题标记为重复。我调查了所有类似的问题,但他们没有我的答案。
【问题讨论】:
-
您可以按照 Apple 的教程获取相同的 Supporting Multiple Interface Orientations 希望这会对您有所帮助。
-
来自您的链接:“当视图控制器呈现在根视图控制器上时,系统行为会以两种方式发生变化。首先,在确定是否使用呈现的视图控制器而不是根视图控制器时"这就是我正在做的......或者我只是不明白他们......请详细解释......
标签: iphone objective-c ios6 uiinterfaceorientation