IOS横竖屏
2015-10-28 00:00
316 查看
1.横竖屏设定
1.1XCode选择设定(整个app有效)选择Project->Target->General->Deployment Info->Device Orientation,勾选需要支持的屏幕方向,比如
:fa-square-o:Portrait
:fa-square-o:Upside Down
:fa-square-o:Landscape Left
:fa-square-o:Landscape Right
1.2.AppDelegate.m文件中代码设定(整个app有效)
在AppDelegate.m中添加方法:
//IOS6及以上 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window NS_AVAILABLE_IOS(6_0){ return UIInterfaceOrientationMaskPortrait; }
1.3.单个View横竖屏设定(单个View有效)
主要依赖于以下几个函数
//当前viewcontroller是否支持转屏 - (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0); //当前viewcontroller支持哪些转屏方向 - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0); //当前viewcontroller默认的屏幕方向 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);
2.相关(ENUM)UIInterfaceOrientation说明
UIInterfaceOrientationMask ->UIInterfaceOrientation的多种组合UIInterfaceOrientationMaskPortrait //竖屏 UIInterfaceOrientationMaskLandscapeLeft //左横屏 UIInterfaceOrientationMaskLandscapeRight //右横屏 UIInterfaceOrientationMaskPortraitUpsideDown //竖屏(颠倒) UIInterfaceOrientationMaskLandscape //横屏 UIInterfaceOrientationMaskAll //所有状态 UIInterfaceOrientationMaskAllButUpsideDown //除颠倒竖屏外
3.转屏时触发哪些函数
<1>调用于翻转之前//一般用来禁用某些控件或者停止某些正在进行的活动,比如停止视频播放。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(2_0,8_0); - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);
<2>调用于翻转的过程中
//一般用来定制翻转后各个控件的位置、大小等。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(3_0,8_0); - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);
<3>调用于整个翻转完成之后。
//一般用来重新启用某些控件或者继续翻转之前被暂停的活动,比如继续视频播放
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation NS_DEPRECATED_IOS(2_0,8_0);
4.判断当前屏幕状态(横/竖)
1. UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 2. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- android实现在横竖屏切换时页面信息不被重置的示例分享
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- IOS开发第三方语音-微信语音