网站建设资讯

NEWS

网站建设资讯

关于IOS屏幕的旋转问题

处理IPhone屏幕的旋转是我们经常遇到的,当你做一个应用既然满足竖屏又要满足横屏,这就要求我们会处理屏幕旋转的问题!

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站建设、网站设计、托克逊网络推广、重庆小程序开发、托克逊网络营销、托克逊企业策划、托克逊品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供托克逊建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

方法一:自动布局

1.将项目中界面的四种手持方式都点上;

2.取消Use Autolayout;

3.选择界面中某个控件然后到属性工具栏中去找到AutoSizing功能,勾选对应的绝对定位的线条

4.重写可以旋转的方法

-(BOOL)shouldAutorotate {     return YES; } -(NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskAll; } 


方法二:手动布局一(通过代码改view种控件的坐标)

1.重写可以旋转的方法

-(BOOL)shouldAutorotate {     return YES; } -(NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskAll; } 
2.勾选上项目中支持的四种手持类型

3.取消Use Autolayout

4.代码实现:

//每当屏幕旋转的时候都会触发一个 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {     //如果是是横屏状态     if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )     {         self.l1.frame = CGRectMake(20, 25, 110, 110);         self.l2.frame = CGRectMake(162, 25, 110, 110);         self.l3.frame = CGRectMake(304, 25, 110, 110);         self.r1.frame = CGRectMake(20, 178, 110, 110);         self.r2.frame = CGRectMake(162, 178, 110, 110);         self.r3.frame = CGRectMake(304, 178, 110, 110);} }

方法三:手动布局二(在xib中新建一个支持横屏的view通过双view切换实现)

1.在xib文件中拖一个view控件,选择Orientation属性为横屏

2.布局好界面

3.将横纵view分别在controller.h文件中创建对应的属性,命名为

@property (retain, nonatomic)IBOutletUIView *landspaceView;

@property (retain, nonatomic)IBOutletUIView *portatiorView;

4.代码实现

宏定义实现角度转弧度

#define degreesToRadia(x) (M_PI * (x) / 180)//参数要加括号 ,尤其是参数附近特别要加括号

-(BOOL)shouldAutorotate {     return YES; } -(NSUInteger)supportedInterfaceOrientations {     return UIInterfaceOrientationMaskAll; } //每当屏幕旋转的时候都会触发一个 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {     //如果是是横屏状态     if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft )     { //        self.l1.frame = CGRectMake(20, 25, 110, 110); //        self.l2.frame = CGRectMake(162, 25, 110, 110); //        self.l3.frame = CGRectMake(304, 25, 110, 110); //        self.r1.frame = CGRectMake(20, 178, 110, 110); //        self.r2.frame = CGRectMake(162, 178, 110, 110); //        self.r3.frame = CGRectMake(304, 178, 110, 110);         self.view = self.landspaceView;         //self.view.transform = CGAffineTransformIdentity;         self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(270));         self.view.bounds = CGRectMake(0, 0, 480, 300);     }     else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)     { //        self.l1.frame = CGRectMake(37, 20, 110, 110); //        self.l2.frame = CGRectMake(37, 162, 110, 110); //        self.l3.frame = CGRectMake(37, 304, 110, 110); //        self.r1.frame = CGRectMake(190, 20, 110, 110); //        self.r2.frame = CGRectMake(190, 162, 110, 110); //        self.r3.frame = CGRectMake(190, 304, 110, 110);         self.view = self.landspaceView;         //self.view.transform = CGAffineTransformIdentity;         self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(90));         self.view.bounds = CGRectMake(0, 0, 480, 300);     }     else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)     {         self.view = self.portatiorView;         self.view.transform = CGAffineTransformIdentity;         self.view.bounds = CGRectMake(0, 0, 320, 460);     }     else if(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)     {         self.view = self.portatiorView;         //self.view = self.landspaceView;         //self.view.transform = CGAffineTransformIdentity;         self.view.transform = CGAffineTransformMakeRotation(degreesToRadia(180));         self.view.bounds = CGRectMake(0, 0, 320, 460);     } } 

模拟屏幕旋转
commond + 方向键
网站标题:关于IOS屏幕的旋转问题
标题链接:http://njwzjz.com/article/gpspjh.html