【iOS】当设备方向已经旋转,转屏效果失效的解决方案

2018-10-22  本文已影响0人  印比八方来

一.问题分析

在开发中,视频界面有强转的需求。当iOS设备处于“禁止旋转”的状态下,强转都是正常的。当iOS设备处于“允许旋转”的状态下,会遇到下面的问题:

二.解决方案

1.横屏 -> 竖屏

// 防止用户先把设备转为横屏,导致屏幕强转横屏失效。
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

2.竖屏 -> 横屏

// 防止用户先把设备转为竖屏,导致屏幕强转竖屏失效。
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
上一篇 下一篇

猜你喜欢

热点阅读