gpt4 book ai didi

iOS 6.0 限制导航 Controller 内的自动旋转?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:35 26 4
gpt4 key购买 nike

我还应该做什么?

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutoRotate
{
return NO;
}

我的 viewController 仍在旋转。


它嵌入在导航堆栈中。如果我将 UINavigationController 子类化,并在那里实现相同的仅纵向模板,并将我的 viewController 嵌入到那个经过调整的 navigationController 中,那么它就可以工作,但我无意在出现 UINavigationController 的任何地方重写我的代码。

此处的最佳做法是什么?

最佳答案

原始答案:无需子类化 - 只需像我在此处的解决方案中描述的那样进行分类: Top-home button portrait orientation in iOS6 simulator not working

基本上,对于 iPhone,UINavigationController 允许旋转除“top home button portrait”之外的所有内容,对于 iPad,它允许旋转所有内容。

所以你要么做一个类别将决定转发给当前事件的 View Controller ,要么做一些静态的事情

UINavigationController-Rotation.h:

@interface UINavigationController (Rotation)
@end

UINavigationController-Rotation.m:

#import "UINavigationController-Rotation.h"

@implementation UINavigationController (Rotation)

#pragma From UINavigationController

- (BOOL)shouldAutorotate {

return NO;
}

- (NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskPortrait;
}

#pragma -

@end

更新:正如 Javier Soto 所指出的,如果有第二个类别在做同样的事情,这可能会导致未定义的行为。在这种情况下,子类化可能是更好的解决方案。

在您知道没有其他类别在做同样的事情的情况下,我仍然认为这是一个可行的、省力的、本地的和务实的解决方案。我对此并不虔诚。自己决定。

关于iOS 6.0 限制导航 Controller 内的自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954087/

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