【UIKit-125-2】#import <UIKit/UIViewController.h>
2015-09-25 19:53
459 查看
【屏幕旋转】
@interface UIViewController (UIViewControllerRotation)
带研究。
+ (void)attemptRotationToDeviceOrientationNS_AVAILABLE_IOS(5_0);
// New Autorotation support.
- (BOOL)shouldAutorotateNS_AVAILABLE_IOS(6_0);//是否可以转屏
- (NSUInteger)supportedInterfaceOrientationsNS_AVAILABLE_IOS(6_0);//支持旋转的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentationNS_AVAILABLE_IOS(6_0);//优先显示的旋转方向
1、全局控制
Info.plist文件中,有一个Supported interface orientations,可以配置整个应用的屏幕方向,此处为全局控制。
2、UIWindow
iOS6的UIApplicationDelegate提供了下述方法,能够指定 UIWindow 中的界面的屏幕方向:
该方法默认值为 Info.plist 中配置的 Supported interface orientations 项的值。
iOS中通常只有一个 window,所以此处的控制也可以视为全局控制。
3、controller
只有以下两种情况:
当前controller是window的rootViewController
当前controller是modal模式的时,orientations相关方法才会起作用(才会被调用),当前controller及其所有的childViewController都在此作用范围内。
4、最终支持的屏幕方向
前面所述的3种控制规则的交集就是一个controller的最终支持的方向;
如果最终的交集为空,在iOS6以后会抛出UIApplicationInvalidInterfaceOrientationException崩溃异常。
@end
@interface UIViewController (UIViewControllerRotation)
带研究。
+ (void)attemptRotationToDeviceOrientationNS_AVAILABLE_IOS(5_0);
[UIViewController attemptRotationToDeviceOrientation];//直接用?可以放在动画里面
// New Autorotation support.
- (BOOL)shouldAutorotateNS_AVAILABLE_IOS(6_0);//是否可以转屏
- (NSUInteger)supportedInterfaceOrientationsNS_AVAILABLE_IOS(6_0);//支持旋转的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentationNS_AVAILABLE_IOS(6_0);//优先显示的旋转方向
1、全局控制
Info.plist文件中,有一个Supported interface orientations,可以配置整个应用的屏幕方向,此处为全局控制。
2、UIWindow
iOS6的UIApplicationDelegate提供了下述方法,能够指定 UIWindow 中的界面的屏幕方向:
该方法默认值为 Info.plist 中配置的 Supported interface orientations 项的值。
iOS中通常只有一个 window,所以此处的控制也可以视为全局控制。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait; /* typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) { UIInterfaceOrientationMaskPortrait = (正向), UIInterfaceOrientationMaskLandscapeLeft = (home键在左边), UIInterfaceOrientationMaskLandscapeRight = (home键在右边), UIInterfaceOrientationMaskPortraitUpsideDown = (倒置), UIInterfaceOrientationMaskLandscape = (home键在左边或者右边), UIInterfaceOrientationMaskAll = (所以方向), UIInterfaceOrientationMaskAllButUpsideDown = (除了倒置都可以), }; */ }
3、controller
只有以下两种情况:
当前controller是window的rootViewController
当前controller是modal模式的时,orientations相关方法才会起作用(才会被调用),当前controller及其所有的childViewController都在此作用范围内。
-(BOOL)shouldAutorotate{ return YES; } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll; /* typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) { UIInterfaceOrientationMaskPortrait = (正向), UIInterfaceOrientationMaskLandscapeLeft = (home键在左边), UIInterfaceOrientationMaskLandscapeRight = (home键在右边), UIInterfaceOrientationMaskPortraitUpsideDown = (倒置), UIInterfaceOrientationMaskLandscape = (home键在左边或者右边), UIInterfaceOrientationMaskAll = (所以方向), UIInterfaceOrientationMaskAllButUpsideDown = (除了倒置都可以), }; */ } -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationUnknown; /* typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown,(非倒置) UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,(正向) UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,(倒置) UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,(home在左侧) UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft(home在右侧) }; */ } }
4、最终支持的屏幕方向
前面所述的3种控制规则的交集就是一个controller的最终支持的方向;
如果最终的交集为空,在iOS6以后会抛出UIApplicationInvalidInterfaceOrientationException崩溃异常。
@end
相关文章推荐
- Uncaught SyntaxError: Failed to execute 'querySelectorAll' on 'Element': '#00' is not a valid select
- 项目:片刻 DAY1 搭建框架结构
- UITableView默认选中第一个cell
- OC基础-NSValue类簇-将复杂数据类型保存为对象
- 【UIKit-125-1】#import <UIKit/UIViewController.h>
- HDOJ 题目3415 Max Sum of Max-K-sub-sequence(单调队列求区间和最大值)
- iOS:下拉刷新控件UIRefreshControl的详解
- 初识duilib
- UITableViewStylePlain与UITableViewStyleGroup样式的对比
- hdoj 3397 Sequence operation 【线段树区间覆盖 + 异或 + 合并】【维护延迟标记的顺序】
- UITableView的registerClass forCellReuseIdentifier用法详解
- 多控制器
- iOS9 新增 UIStackView 官方文档翻译
- 史上最简单的自定义UITabelView编辑状态的删除按钮
- UGUI基本概念
- WeiFenLuo.winFormsUI.Docking.dll的使用(停靠效果)
- WeiFenLuo.winFormsUI.Docking.dll的使用(停靠效果)
- UIView相对于屏幕的frame
- 生成所有sequence Yahtzee part 1
- Block在UITableViewcell中的正向和反向传值