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 ...
随机推荐
- 【C++库函数】stringstream-类型转换&&字符分割
继续填坑٩(•̤̀ᵕ•̤́๑),这次是 stringstream的内容,最初是看到它可以把字符串直接输出成int类型,惊了,但是一直不是很懂.在网上查了很多资料,才终于差不多理解.stringstre ...
- L3-002 特殊堆栈 (双数组模拟栈)
堆栈是一种经典的后进先出的线性结构,相关的操作主要有"入栈"(在堆栈顶插入一个元素)和"出栈"(将栈顶元素返回并从堆栈中删除).本题要求你实现另一个附加的操作: ...
- vue-cli3title标签中的htmlWebpackPlugin.options.title
https://blog.csdn.net/weixin_56650035/article/details/119355625
- 每天学五分钟 Liunx 0101 | 服务篇:创建进程
创建子进程 上一节说过创建子进程的三种方式: 1. fork 复制进程:fork 会复制当前进程的副本,产生一个新的子进程,父子进程是完全独立的两个进程,他们掌握的资源(环境变量和普通变量)是一样的. ...
- 安装MicroStation软件、Terrasolid插件的方法
本文介绍在Win10电脑中,安装MicroStation软件与Terrasolid插件合集的详细方法. 首先,我们需要有MicroStation软件与Terrasolid插件合集的安装包:这些 ...
- SV 设计特性
过程语句块特性 ABC 过程块语句 always_comb 防止多驱动的问题:赋值块左侧的语句无法被另一个过程块赋值 if语句没有写else,sv会提示警告,sv认为是latch always不会再仿 ...
- 【Git】用法小记
解决windows环境下的CRLF与unix环境下的LF问题,windows提交时CRLF=>LF,签出时LF=>CRLF,unix环境保留 git config --global cor ...
- [转帖]lsblk命令详解
https://www.cnblogs.com/ishmaelwanglin/p/11043918.html lsblk命令用来查看block设备的信息. 主要应用场景: 获取wwnid,获取块设备列 ...
- [转帖]谈 JVM 参数 GC 线程数 ParallelGCThreads 合理性设置
https://my.oschina.net/u/4090830/blog/7926038 1. ParallelGCThreads 参数含义 在讲这个参数之前,先谈谈 JVM 垃圾回收 (GC) 算 ...
- Oracle 建立数据库dblink 然后同步部分表内容的总结
同步处理部分数据 背景 最近在项目上发现两个分库进行数据同步时部分内容同步存在问题. 最简单的方法是导表,但是害怕有其他关联信息异常, 所以同事想到了dblink的方式. 这里简单整理一下 同事用到的 ...