強(qiáng)制橫屏大全

最近做直播,豎屏的項(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參考)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容