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 一键部署 Stable Diffusion?
作者|寒斜(阿里云智能技术专家) 前文回顾 AI 作画火了,如何用 Serverless 函数计算部署 Stable Diffusion? [自己更换模型]如何用 Serverless 一键部署 St ...
- <vue 基础知识 2、插值语法> v-once,v-html,v-text,v-pre,v-cloak
代码结构 一. Mustache 1.效果 展示如何将数据展示在页面上 2.代码 01-Mustache.html <!DOCTYPE html> <html lang=&q ...
- 【转载】内存基本概念-node, zone ,page
1. Linux描述物理内存 在linux 内存管理(一)中介绍了UMA和NUMA,Linux通过巧妙办法把UMA和NUMA的差别隐藏了起来,所谓的UMA其实就是只有一个结点的NUMA.内存的每个结点 ...
- Vue项目中使用 tinymce 富文本编辑器的方法,附完整源码
Vue项目中使用 tinymce 富文本编辑器的方法,附完整源码 https://blog.csdn.net/snsHL9db69ccu1aIKl9r/article/details/11432414 ...
- treeselect 表单验证解决方法
https://www.cnblogs.com/wxqworld/p/11203603.html
- P1032
写这道不算难的题目是我遇到了不少问题,复述以下过程吧. 由于数据很水,这道题用不到KMP算法,只要使用朴素算法进行字符串比对就可以了. 1 首先,我错误的选择了dfs算法,导致了TLE的发生.这类求最 ...
- kafka常用操作
kafka运维常用查询操作总结以下几点: kafka生产和消费消息测试 发送:bin/kafka-console-producer.sh --broker-list 10.46.200.165:909 ...
- Solon v2.6.5 发布(助力信创)
Solon 是什么框架? Java "生态级"应用开发框架.从零开始构建,有自己的标准规范与开放生态(历时六年,具备全球第二级别的生态规模). 相对于 Spring,有什么特点? ...
- 【SHELL】反斜杠解决多个shell实例扩展
本意是想获取代码仓相对路径,代码如下 base_dir=`pwd` repo forall -c '{ user_dir=$(realpath --relative-to="$bas ...
- 【rt-thread】SConscript文件添加格式必须是4空格开头
SConscript文件添加格式必须是4空格开头,TAB或其他数量的空格均错误