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

iOS 的Viewcontroller只支持一个屏幕方向,弹出不同方向,旋转

2018年05月28日 ⁄ 综合 ⁄ 共 701字 ⁄ 字号 评论关闭

环境:IOS7,iPhone5。大家都知道写法:

// 是否支持屏幕旋转
- (BOOL)shouldAutorotate {
    return YES;
}
// 支持的旋转方向
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;//UIInterfaceOrientationMaskAllButUpsideDown;
}
// 一开始的屏幕旋转方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

如果我的原VC是横屏,但是弹出来一个要竖屏的怎么办?看代码:

方法如下:

// 是否支持屏幕旋转
- (BOOL)shouldAutorotate {
    return NO;
}

/* // 支持的旋转方向  不能重写这个函数,否则崩溃
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAllButUpsideDown;//UIInterfaceOrientationMaskAllButUpsideDown;
}*/

// 一开始的屏幕旋转方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

抱歉!评论已关闭.