iOS设置整体支持竖屏,部分页面可支持横屏:在iOS开发中有时候会遇到部分页面支持横屏,如视频播放页。但是大部分页面支持竖屏。具体操作及代码如下。
一:首先项目的targets中需要支持左旋转,右旋转。
二:AppDelegate的.h文件添加一个属性allowRotation控制是否允许旋转 #import #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; /** * 是否允许旋转 YES:允许 NO:不允许 */ @property(nonatomic,assign) BOOL allowRotation; @end 三:AppDelegate的.m文件修改这个方法- (UIInterfaceOrientationMask)application:(UIApplication )application supportedInterfaceOrientationsForWindow:(nullable UIWindow )window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED; - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if (self.allowRotation) { return UIInterfaceOrientationMaskAll; } return UIInterfaceOrientationMaskPortrait; } 四:在需要设置旋转的控制器中引入头文件:#import “AppDelegate.h” 页面出现时调用下面代码,要把appdelegate.allowRotation置YES AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate; appdelegate.allowRotation=YES; 退出界面时调用下面代码,要把appdelegate.allowRotation置NO AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate; appdelegate.allowRotation=NO;
如对本文有疑问, 点击进行留言回复!!
Codeforces Round #657 (Div. 2) C题
hdu2222 Keywords Search(ac自动机模板-kuangbin)
IOS开发控件视图day08:监听文本框状态设置按钮状态不可点击且变灰
网友评论