gpt4 book ai didi

ios - Objective-C - 模态内的旋转甚至 shouldAutoRotate = false

转载 作者:行者123 更新时间:2023-11-29 11:07:10 27 4
gpt4 key购买 nike

即使我将 shouldAutoRotate 设置为 false,我也有一个正在旋转的 View (InfoVC)。这是打开 View 的代码(在模式内)

- (IBAction)presentInfoVC:(id)sender{
InfoVC *infoVC = [[InfoVC alloc] init];
UINavigationController *infoNVC = [[UINavigationController alloc] initWithRootViewController:infoVC];

UIImage *img =[UIImage imageNamed:@"image.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];



infoNVC.navigationBar.tintColor = [UIColor lightGrayColor];
[infoNVC.navigationBar.topItem setTitleView:imgView];
[imgView release];

[self presentModalViewController:infoNVC animated:YES];

[infoVC release];

}

以及应该避免此 View 旋转的代码(在 InfoVC.m 中):

- (BOOL)shouldAutorotate
{
return FALSE;
}

怎么了?

问候!

最佳答案

您可以使用类别来执行相同的任务,而不是创建 UINavigationController 的子类(如果 UINavigationController 的所有实例都需要它)。它比子类化方法轻量得多,并且不需要您为预先存在的 UINavigationController 交换类类型。

具体做法如下:

UINavigationController+NoRotate.h

@interface UINavigationController(NoRotate) 
- (BOOL)shouldAutorotate;
@end

UINavigationController_NoRotate.m

#import "UINavigationController+NoRotate.h"

@implementation UINavigationController (NoRotate)

- (BOOL)shouldAutorotate
{
return NO;
}

@end

从那时起,如果您需要一个不再旋转的UINavigationController,只需在需要的地方导入UINavigationController+NoRotate.h。由于类别覆盖将影响该类的所有实例,如果您仅在少数情况下需要此行为,那么您将需要子类化 UINavigationController,并覆盖 -(BOOL)shouldAutorotate

关于ios - Objective-C - 模态内的旋转甚至 shouldAutoRotate = false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13128782/

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