【UIKit-125-2】#import <UIKit/UIViewController.h>



【屏幕旋转】

@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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值