iOS 屏幕旋转的设置方法
NSNumber *orientationTarget = [NSNumber numberWithInteger:isLaunchScreen ? UIInterfaceOrientationLandscapeRight : UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
// ,AppDelegate代理是App启动后的动态更改,可以覆盖启动前的设置,所以它的优先级最大
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if isLaunchScreen {
return .landscapeRight
} else {
return .portrait
}
}
// 1.是否支持屏幕旋转,只有返回true, 下面的两个方法才会执行
open var shouldAutorotate: Bool { get } // 2.页面支持的屏幕方向
@available(iOS 6.0, *)
open var supportedInterfaceOrientations: UIInterfaceOrientationMask { get } // 3.页面进入时的屏幕方向
@available(iOS 6.0, *)
open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { get }
UINavigationController->UIViewController
UINavigationController->UIViewController
UINavigationController->UIViewController
UINavigationController->UIViewController
verride var shouldAutorotate: Bool {
return ((self.selectedViewController?.shouldAutorotate) != nil)
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return self.selectedViewController?.supportedInterfaceOrientations
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return self.selectedViewController?.preferredInterfaceOrientationForPresentation
}
override var shouldAutorotate: Bool {
return self.topViewController?.shouldAutorotate
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return self.topViewController.supportedInterfaceOrientations
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return self.topViewController.preferredInterfaceOrientationForPresentation
}
// ViewController
override var shouldAutorotate: Bool {
return true
} override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscape
} override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeLeft
}
/*
This method is called when the view controller's view's size is changed by its parent (i.e. for the root view controller when its window rotates or is resized). If you override this method, you should either call super to propagate the change to children or manually forward the change to children.
*/
@available(iOS 8.0, *)
func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
open func layoutSubviews() {
if UIApplication.shared.statusBarOrientation == UIInterfaceOrientation.landscapeLeft {
旋转判断
}
}
iOS 屏幕旋转的设置方法的更多相关文章
- iOS屏幕旋转 浅析
一.两种orientation 了解屏幕旋转首先需要区分两种orientation 1.device orientation 设备的物理方向,由类型UIDeviceOrientation表示,当前设备 ...
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
iTouch,iPhone,iPad设置都是支持旋转的,如果我们的程序能够根据不同的方向做出不同的布局,体验会更好. 如何设置程序支持旋转呢,通常我们会在程序的info.plist中进行设置Suppo ...
- IOS屏幕旋转思路和实践
这段时间同事在做一个直播项目,项目有个需求:一个界面需要手动设置屏幕的方向,设置好之后方向不能变化.完成这个需求花了特别大的精力,归因是网上关于屏幕旋转的知识比较凌乱,解决问题花费不少时间,最后决定把 ...
- ios 屏幕旋转的问题
在ios6之前我们旋转屏幕只需要实现shouldAutorotateToInterfaceOrientation就行了 - (BOOL)shouldAutorotateToInterfaceOrien ...
- iOS 屏幕旋转 nav+tabbar+present(网页) 2016
如题,最近一个app架构为 nav + tabbar ,需求是 在点击tabbar中的一个菜单项时,弹出网页,该网页需要横屏显示,其他页面不变 都保持竖屏. XCode Version 7.2.1 ...
- ios 屏幕方向的设置
ref: http://www.cnblogs.com/niit-soft-518/p/5611298.html 实际的项目需求.root是TabBarController,里面有4个navigati ...
- iOS屏幕旋转
三种方法 需求:全局主要是竖屏 个别界面需要横屏
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转-b
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...
- 【转】IOS设备旋转的内部处理流程以及一些【优化建议】
加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向: typedef NS_ENUM(NSInteger, UIDeviceOrienta ...
随机推荐
- Serverless 时代开启,云计算进入业务创新主战场
作者 | 于洪涛 "我们希望让用户做得更少而收获更多,通过 Serverless 化,让企业使用云服务像用电一样简单." Serverless 化正在成为全新的软件研发范式,阿里云 ...
- 人人都是 Serverless 架构师 | “盲盒抽奖”创意营销活动实践
作者 | 寒斜 & 江昱 当 Serverless 与低代码这两个不同的技术共同相交于同一个业务时会有怎样的价值展现?本文以 "盲盒抽奖" 这个 Serverless De ...
- 七、java操作swift对象存储(动态大对象)
系列导航 一.swift对象存储环境搭建 二.swift添加存储策略 三.swift大对象--动态大对象 四.swift大对象--静态态大对象 五.java操作swift对象存储(官网样例) 六.ja ...
- 写了个移动端可滑动(惯性滑动&回弹)Vue导航栏组件 ly-tab
https://www.imooc.com/article/23768?block_id=tuijian_wz https://blog.csdn.net/weixin_44614772/articl ...
- freeswitch配置SBC实例
概述 freeswitch 是一款好用的开源软交换平台. 随着voip客户的发展和运营商网络的升级换代,SBC在对接测试中的应用场景越来越多. freeswitch通过简单的安装配置即可满足大部分SB ...
- Redis 常用五种数据类型编码
转载请注明出处: 目录 Redis 的五种数据结构 Redis 数据结构的内部编码 1.String 1.1 常用命令 1.2 内部编码 1.3 典型使用场景 2. Hash 2.1 常用命令及时间复 ...
- java 文件上传 :MultipartFile 类型转换为file类型
通过前台进行文件上传并保存服务器. 1.从前台解析得到的文件类型为 MultipartFile 类型,在进行解析的时候,我们需要将 MultipartFile 类型转换为file类型,然后将文件上传到 ...
- 你不知道的JavaScript APIs
前言 在本文中,将介绍一些鲜为人知但却非常有用的API,如: Page Visibility API Web Share API Broadcast Channel API International ...
- Spring Cloud 系列:Seata 中TCC模式具体实现
概述 https://seata.io/zh-cn/docs/dev/mode/tcc-mode https://seata.io/zh-cn/docs/user/mode/tcc TCC模式与AT模 ...
- SV 自定义数据类型
概述 自定义类型 枚举类型 定义枚举值 自定义枚举类型 枚举类型之间进行赋值是可以的 枚举类型可以赋值给整型,整型不能直接赋值给枚举类型 枚举类型 + 1 ==> 会进行隐式的转换,枚举类型转换 ...