gpt4 book ai didi

ios - 如何锁定 UIAlertController 方向?

转载 作者:搜寻专家 更新时间:2023-10-31 21:47:44 24 4
gpt4 key购买 nike

在我的应用程序中,我只有一个横向模式的 UIViewController,如果我在应用程序内导航,它工作正常。但是,当我从横向 View Controller 显示 UIAlertController(用于显示警报 View )并更改设备方向时,它会更改横向 View Controller 的方向。我尝试了不同的解决方案,例如:

UIAlertView crashs in iOS 8.3

iOS 8.3 supported orientations crashs

但这些都不适合我。如何锁定 UIAlertController 的方向?注意:我的应用支持 iOS9

最佳答案

这是另一种解决方案,它通过这种方式锁定 UIAlertController 中的方向,从而避免失去在 viewController 中旋转屏幕的能力。

PXCustomUIAlertController.h

#import <UIKit/UIKit.h>

@interface PXCustomUIAlertController : UIAlertController
@end

PXCustomUIAlertController.m

#import "PXCustomUIAlertController.h"

@interface PXCustomUIAlertController ()
@end

@implementation PXCustomUIAlertController


- (instancetype)init
{
self = [super init];
return self;
}


-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

@end

然后你可以像这样使用重要的类:

    PXCustomUIAlertController *alertController = [PXCustomUIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];

...

关于ios - 如何锁定 UIAlertController 方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37341012/

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