iOS屏幕旋转

作者: 且行且珍惜_iOS | 来源:发表于2016-05-04 11:27 被阅读896次

UIInterfaceOrientation方向枚举:
UIInterfaceOrientationPortrait //home健在下
UIInterfaceOrientationPortraitUpsideDown //home健在上
UIInterfaceOrientationLandscapeLeft //home健在左
UIInterfaceOrientationLandscapeRight //home健在右

旋转屏幕时触发的函数:
//旋转方向发生改变时
-(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 {
}

如果项目中用了navigationViewController, 那么就应该新建一个uinavigationViewController的子类,然后在这个类里面写上下面的代码,在使用的时候就用自定义的这个navCtr, 就是说需要在根视图里面控制

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
return toInterfaceOrientation != UIDeviceOrientationPortraitUpsideDown; 
} 
 - (BOOL)shouldAutorotate { 
if ([self.topViewController isKindOfClass:[AddMovieViewController class]]) {       // 如果是这个 vc 则支持自动旋转 
return YES; 
} 
return NO; 
} 
- (NSUInteger)supportedInterfaceOrientations { 
return UIInterfaceOrientationMaskAllButUpsideDown; 
}

1.Window级别的控制
对于UIApplicationDelegate的这个方法声明,大多数情况下application就是当前的application,而window通常也只有一个。所以基本上通过window对横屏竖屏interfaceOrientation的控制相当于全局的。
//每次试图切换的时候都会走的方法,用于控制设备的旋转方向.
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (_isRotation) {
return UIInterfaceOrientationMaskLandscape;
}else {
return UIInterfaceOrientationMaskPortrait;
}
}


2.Controller层面的控制
//哪些页面支持自动转屏
- (BOOL)shouldAutorotate{

return YES;
}
// viewcontroller支持哪些转屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAllButUpsideDown;
 }

3.使得特定ViewController坚持特定的interfaceOrientation.
当然,使用这个方法是有前提的,就是当前ViewController是通过全屏的 Presentation方式展现出来的.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);


4.当前屏幕方向interfaceOrientation的获取.

 有3种方式可以获取到“当前interfaceOrientation”:
controller.interfaceOrientation,获取特定controller的方向
[[UIApplication sharedApplication] statusBarOrientation] 获取状态条相关的方向
[[UIDevice currentDevice] orientation] 获取当前设备的方向

相关文章

  • 屏幕旋转

    屏幕旋转 推荐文档 了解UIWindow——UIWindow实践 iOS屏幕旋转问题总结 IOS:屏幕旋转与变换 ...

  • OC - 屏幕旋转(自动旋转、手动旋转、兼容iOS6之前系统)

    导读: 一、iOS6之前屏幕旋转知识了解 二、iOS6(包括iOS6)之后屏幕旋转知识了解 三、自动旋转具体操作 ...

  • 屏幕旋转和弹出框

    iOS中控制屏幕旋转相关方法 shouldAutorotate:是否支持屏幕旋转 alertView:clicke...

  • iOS Rotation

    iOS屏幕旋转学习笔记iOS开发中使用屏幕旋转功能的相关方法 1、基本知识点解读 了解屏幕旋转首先需要区分两种 o...

  • iOS传感器:实现一个随屏幕旋转的图片

    iOS传感器:实现一个随屏幕旋转的图片 iOS传感器:实现一个随屏幕旋转的图片

  • iOS 屏幕旋转处理

    iOS 屏幕旋转处理 在 iOS 设备上, 屏幕旋转是个挺坑比的问题. 苹果希望 app 对整个 app 做统一的...

  • iOS屏幕旋转

    方式一 假旋转 修改view的transform,通过旋转来实现横屏 工程配置 重写shouldAutorotat...

  • iOS 屏幕旋转

    第一种 在基类控制器,RootTableViewController,RootNaviViewController...

  • iOS屏幕旋转

    一、两种方向的区别 设备方向设备的物理方向,由类型UIDeviceOrientation表示,当前设备方向获取方式...

  • iOS屏幕旋转

    iOS屏幕旋转 1.基本属性和概念 shouldAutorotate supportedInterfaceOrie...

网友评论

本文标题:iOS屏幕旋转

本文链接:https://www.haomeiwen.com/subject/wbprrttx.html