gpt4 book ai didi

ios - 在 iPad Pro 中不工作的单个 UIViewController 上禁用自动旋转

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

我想在 iPhone 和 iPad 中锁定单个 View Controller 。下面的代码在 iPhone 4、5、6 iPad、iPad 2、iPad 视网膜上完美运行。但不适用于 iPad pro。

@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
{
return YES;
}
@end

上面的代码写在我不想旋转的 View Controller 中。

最佳答案

在 View Controller 中写下面的代码,你想在纵向模式下锁定哪个 View Controller

@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate
{
return YES;
}
@end

#pragma mark Orientation
-(BOOL)shouldAutorotate
{
[super shouldAutorotate];
return NO;
}
-(NSUInteger) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
[super preferredInterfaceOrientationForPresentation];
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}

现在在您的 plist 文件中进行以下更改 enter image description here

关于ios - 在 iPad Pro 中不工作的单个 UIViewController 上禁用自动旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36146605/

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