gpt4 book ai didi

iphone - iOS6 中未调用 shouldAutoRotate 方法

转载 作者:行者123 更新时间:2023-12-03 19:43:49 24 4
gpt4 key购买 nike

我有一个 UIViewController 详细 View ,它是从 UINavigationController 中的 UITableView 推送的。在 UIViewController 中,我添加了许多 subview (例如 UITextViewUIImageView)。

iOS5中,如果我的图片 View 放大,我使用此代码来停止自动旋转:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (scrollView.isZoomed) {
return NO;
}
else {
return YES;
}

}

我正在尝试使用以下方法在 iOS6 下实现相同的目标:

- (BOOL)shouldAutorotate {
return FALSE;
}

但是,此方法永远不会被调用,并且应用程序会继续旋转。

有人可以帮忙吗?

最佳答案

如果您有一个导航 Controller 来管理这些 View ,则不会调用 shouldAutorotate 方法。您必须继承 UINavigationController 并重写方法 shouldAutorotatesupportedIntervalOrientations

来自文档:

Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate

编辑-----

正如 Lomax 在下面提到的,Apple 不鼓励子类化 UINavigationController。您应该尝试使用类别 ( this SO question explains it well ):

@implementation UINavigationController 
-(BOOL)shouldAutorotate
{
// your code
}

-(NSUInteger)supportedInterfaceOrientations
{
(...)
}

@end

关于iphone - iOS6 中未调用 shouldAutoRotate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13588325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com