关于IOS屏幕的旋转问题
2013-08-13 16:39
375 查看
处理IPhone屏幕的旋转是我们经常遇到的,当你做一个应用既然满足竖屏又要满足横屏,这就要求我们会处理屏幕旋转的问题!
方法一:自动布局
1.将项目中界面的四种手持方式都点上;
2.取消Use Autolayout;
3.选择界面中某个控件然后到属性工具栏中去找到AutoSizing功能,勾选对应的绝对定位的线条
4.重写可以旋转的方法
方法二:手动布局一(通过代码改view种控件的坐标)
1.重写可以旋转的方法
3.取消Use Autolayout
4.代码实现:
方法三:手动布局二(在xib中新建一个支持横屏的view通过双view切换实现)
1.在xib文件中拖一个view控件,选择Orientation属性为横屏
2.布局好界面
3.将横纵view分别在controller.h文件中创建对应的属性,命名为
@property (retain,
nonatomic) IBOutlet UIView *landspaceView;
@property (retain,
nonatomic) IBOutlet UIView *portatiorView;
4.代码实现
宏定义实现角度转弧度
#define degreesToRadia(x) (M_PI * (x) / 180)//参数要加括号 ,尤其是参数附近特别要加括号
模拟屏幕旋转
commond + 方向键
方法一:自动布局
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) IBOutlet UIView *landspaceView;
@property (retain,
nonatomic) IBOutlet UIView *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 + 方向键
相关文章推荐
- 关于iOS6.0 屏幕旋转的问题
- 关于IOS屏幕的旋转问题
- ios 关于禁止屏幕旋转问题的解决
- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- 关于IOS屏幕旋转的几个问题1.常规设置2.个别页面强制固定横竖屏
- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- iOS开发:关于屏幕旋转问题
- 转载 -- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- iOS关于适配屏幕的问题_2
- ios 随手篇 关于ios5/ios6屏幕旋转问题
- ios 3D引擎 SceneKit 开发(5) --关于旋转的几点问题(2)
- iOS关于iPhone6和iPhone6 Plus的屏幕适配问题
- 关于android旋转屏幕时activity重建和android 转屏 onConfigurationChanged 不会执行的问题
- 关于屏幕的旋转问题
- ios 关于3d旋转问题
- ios 屏幕旋转的问题
- iOS 有关旋转屏幕的问题
- iOS屏幕旋转问题
- 关于iOS拍照图片旋转90度问题
- iOS 有关旋转屏幕的问题