现在的位置: 首页 > 综合 > 正文

Navi PushVC及Present VC的屏幕旋转

2018年08月03日 ⁄ 综合 ⁄ 共 1486字 ⁄ 字号 评论关闭

1. 如果没有在Navi中, 则使用下面三个方法来决定屏幕的旋转方向。 同样, 对针present出来的VC也用下面的方法来决定

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    returnUIInterfaceOrientationPortrait;

}

- (BOOL)shouldAutorotate {

    return
NO;

}

- (NSUInteger)supportedInterfaceOrientation {

    returnUIInterfaceOrientationMaskPortrait;

}

2. 如果在Navi中, 则默认Navi下的VC无法控制自己的屏幕旋转, 应该是因为Navi的push动画的原因吧。 

3. 如果在Navi中, 又想Navi下的VC自己去控制自己的屏幕旋转, 可以在Navi中如下实现,然后在自己的VC中分别控制屏幕的旋转, 实现后发现还是有些问题。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return [self.topViewControllershouldAutorotate];

}

-(NSUInteger)supportedInterfaceOrientations

{

    return [self.topViewControllersupportedInterfaceOrientations];

}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    returnUIInterfaceOrientationPortrait;

}

4. 建议还是在Navi中来限制屏幕的旋转, 然后控制特别需要旋转的界面的弹出方式为present

5. 对于某些界面,以present出来的界面为例, 如果需要针对某些条件来设置屏幕朝向, 可以如下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

   
if (self.forVedioPlayer ==
YES) {

       
return YES;

    }else {

       
return NO;

    }

}

-(NSUInteger)supportedInterfaceOrientations

{

   
if (self.forVedioPlayer ==
YES) {

        return
UIInterfaceOrientationMaskLandscape;

    }else {

        return
UIInterfaceOrientationMaskPortrait;

    }

}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

   
if (self.forVedioPlayer ==
YES) {

        return
UIInterfaceOrientationLandscapeLeft;

    }else {

        return
UIInterfaceOrientationPortrait;

    }

}

下面这篇文章讲得较好,http://blog.sina.com.cn/s/blog_76264a170101e5lb.html

抱歉!评论已关闭.