-(BOOL)shouldAutorotate{
//用来设置当前视图控制器是否支持旋转
return YES;
}
//设置屏幕旋转方向 系统默认支持三个方向的旋转 竖直 左横屏 右横屏
-(NSUInteger)supportedInterfaceOrientations{
// UIInterfaceOrientationMaskPortrait 竖直方向
// UIInterfaceOrientationMaskLandscapeLeft 左横屏
// UIInterfaceOrientationMaskLandscapeRight 右横屏
// UIInterfaceOrientationMaskLandscape 左横屏 右横屏
// UIInterfaceOrientationMaskAll 上下左右都有
return UIInterfaceOrientationMaskAll;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
//当屏幕将要旋转时 触发 (此时屏幕还未旋转)
//当屏幕旋转时 需要暂停音乐播放,视频播放,关闭用户交互
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
//屏幕旋转时
//如果想要在屏幕旋转时添加自定义的动画
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
//当屏幕旋转完成之后触发
//继续音乐,视频 播放 打开用户交互
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
[objc] view plaincopyprint?
<pre name="code" class="objc">//系统UIView 的方法
-(void)layoutSubviews{
//当屏幕每次旋转时都会触发视图重新布局方法 为视图上的子视图重新布局
[super layoutSubviews];
//对子视图重新布局.根据屏幕旋转的方向 决定布局的样式
// 1 获取屏幕旋转方向
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationPortrait:
NSLog(@"竖直方向(正)");
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(@"竖直方向(倒)");
_butten.frame = CGRectMake(50, 240, 220, 40);
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
//设置横屏时视图的显示样式
_butten.frame = CGRectMake(320, 150, 60, 30);
break;
default:
break;
}
}
iOS屏幕旋转
最新推荐文章于 2021-01-16 10:09:44 发布