最近做直播,豎屏的項(xiàng)目需要支持橫屏,經(jīng)過各種惡心的深坑,搜集的大全?
1.在APPDelegate添加項(xiàng)目支持方向,需要做一個(gè)單例,因?yàn)樾枰秩バ薷闹С洲D(zhuǎn)的方向
解釋:
#pragma mark - - orientation
// 是否支持轉(zhuǎn)屏
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
// 返回nav棧中的最后一個(gè)對(duì)象支持的旋轉(zhuǎn)方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
// 返回nav棧中最后一個(gè)對(duì)象,堅(jiān)持旋轉(zhuǎn)的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
2.在需要轉(zhuǎn)屏的時(shí)候調(diào)用
// 修改項(xiàng)目支持的方向
[SupportedInterfaceOrientations sharedInstance].orientationMask = UIInterfaceOrientationMaskLandscapeRight;
// 強(qiáng)制轉(zhuǎn)屏
NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
可以參考我的Demo,喜歡可以點(diǎn)贊:https://github.com/15088138451/i-m-fly ?
參考文檔:http://www.itdecent.cn/p/6c45fa2bb970 (BUG參考)
http://www.itdecent.cn/p/5c773628caa6 (解釋)
http://www.cnblogs.com/niit-soft-518/p/5611298.html (BUG參考)