viewController 支持的屏幕方向

来源:互联网 发布:人工智能利弊英语作文 编辑:程序博客网 时间:2024/06/04 19:59

 /**控制器设置支持的方向 */

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

    /**

     UIInterfaceOrientationMaskPortrait = 竖屏,

     UIInterfaceOrientationMaskLandscapeLeft = 横屏左边,

     UIInterfaceOrientationMaskLandscapeRight = 横屏右边

     UIInterfaceOrientationMaskPortraitUpsideDown = 竖屏下边

     UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),横屏左右边

     UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),所有

     UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),

     } __TVOS_PROHIBITED;

     

     */

    returnUIInterfaceOrientationMaskAll;

}


// - 设置 viewController 的屏幕方向

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//支持旋转
-(BOOL)shouldAutorotate{
     return YES;
}
//
//支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

 //一开始的方向  很重要
 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeLeft;
}

0 0