公司项目2.x版本了, 目前有需求在某一页面横屏并且要用键盘输入;
之前 Device Orientation 只支持 竖屏,
现在要加上landscape right 了;
请问,如何做才能尽量不影响其他一定是竖屏的页面,
解决方案
通过修改单例对象属性到达横竖屏切换.
如使用AppDelegate
, 在AppDelegate.h
中添加一个属性
@property (nonatomic, assign) UIInterfaceOrientationMask orientationMask;
在AppDelegate.m
, 实现supportedInterfaceOrientationsForWindow
方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 设置默认值, 为竖屏 _orientationMask = UIInterfaceOrientationMaskPortrait; return YES;}// window中支持的屏幕显示方向- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return _orientationMask;}
在横屏控制器中, 修改orientationMask
的值
// 支持 横屏 竖屏[(AppDelegate *)[UIApplication sharedApplication].delegate setOrientationMask:UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight];
退出当前控制器时, 还原竖屏设置
// 支持 竖屏[(AppDelegate *)[UIApplication sharedApplication].delegate setOrientationMask:UIInterfaceOrientationMaskPortrait];