【问题标题】:How to lock UIAlertController's orientation?如何锁定 UIAlertController 方向?
【发布时间】:2016-05-20 07:52:02
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
swift
ios9
uialertcontroller
【解决方案1】:
这是其他解决方案,只需在 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];
...
【解决方案2】:
如果您想锁定整个应用的方向:如果您正在使用 XCode,请展开左侧的文件概览。单击 App(最高元素),它旁边应该有 XCode 图标。然后您可以在 Device Orientation 下选择支持的状态。
如果您只想锁定一个视图的方向:
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}