1. iOS有四个方向的旋转,为了保证自己的代码能够支持旋转,我们必须首先处理一个函数:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
2. 这个函数时用来确定我们的应用所支持的旋转方向。如果想要支持每个方向则直接返回YES就行,还可以单独判断某一方向:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
//left
}
if (interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
//right
}
if (interfaceOrientation==UIInterfaceOrientationPortrait) {
//up
}
if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
//down
}
return YES;
}
3. 当然旋转还有一些函数可触发:
//旋转方向发生改变时
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
//视图旋转动画前一半发生之前自动调用
-(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
//视图旋转动画后一半发生之前自动调用
-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
}
//视图旋转之前自动调用
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
//视图旋转完成之后自动调用
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}
//视图旋转动画前一半发生之后自动调用
-(void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}
分享到:
相关推荐
应用ios8新特性,ios8下tableviewcell内容自适应
ios屏幕旋转
UITableViewCell 动态高度计算 适用于ios8.0后 支持UITextView输入动态改变高度。
解决iOS5.1与iOS6.0的屏幕旋转兼容的demo
根据图片比例自适应的瀑布流,非常适合图片社交软件的使用 因大小限制请去: https://github.com/jimmywu1992/JimmyLayout.git 下载。
自定义Alert,自适应高度
swift ,使用autolayout + storyboard 最外层tableview列表,cell里面嵌套了tableview,自适应内容,cell里的tableview不可滑动,内容全部显示,且文字分行显示,不用设置cell的高度直接可以自适应内容
纯代码高度自适应
IOS屏幕旋转完美解决,不使用私有方法 适合场景:App中启动其它游戏或者组件时屏幕方向问题 解决办法:使用多个UIViewController之间的切换实现屏幕旋转
根据加载的html内容,自适应高度
主要介绍了iOS 中根据屏幕宽度自适应分布按钮的实例代码,本文给大家分享两种方式,代码简单易懂,需要的朋友可以参考下
iOS 高度封装自适应表单(重构版) Github 地址: https://github.com/RockChanel/SWForm 简书地址: https://www.jianshu.com/p/2d2f742622fa
iOS 高度封装自适应表单(编辑及附件) 快捷构造复杂表单系统,包含编辑、附件功能 详细说明戳这里:https://www.jianshu.com/p/554c6c4c42d2
根据加载的html内容,自适应高度
iOS强制屏幕旋转兼容iOS11到iOS17
支持Cell和Tableview高度自适应,Label和ScrollView内容自适应,致力于做最简单易用的AutoLayout库。) 图示demo为 “SDAutoLayout实现的对scrollview多种形式的自动布局以及contentsize自适应(带动画效果)” ...
一个用纯代码完成的自适应屏幕的iOS App UI部分代码,包括可以安装运行的ipa和app的界面流程图。努力一周时间完工,本以为可以挣点小钱的,结果用户说他们的后台功能只能用故事版整合,所以代码无用,就杯具了。放在...
自定义headerview,自适应header的高度
github地址: https://github.com/RockChanel/SWForm 欢迎 Star !!!!!