iOS 開發(fā)之需要的頁面只支持豎屏

好久沒有寫過簡書了呢,今天就來記錄一下項目中遇到的一個小問題:個別頁面只支持橫屏或是豎屏,其他頁面支持橫豎屏。
參考博客:http://www.cnblogs.com/lear/p/5051818.html
我這邊是帶導(dǎo)航欄的,實現(xiàn)也挺簡單的,直接上代碼吧
創(chuàng)建導(dǎo)航欄的類目,并在.m文件實現(xiàn)下面的方法

 //是否允許轉(zhuǎn)屏
- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}
//viewController所支持的全部旋轉(zhuǎn)方向
- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}
  //viewController初始顯示的方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

下面在需要只支持豎屏的頁面再重寫一遍上面的方法就行了,如下:

- (BOOL)shouldAutorotate{
    //不允許轉(zhuǎn)屏
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    //viewController所支持的全部旋轉(zhuǎn)方向
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //viewController初始顯示的方向
    return UIInterfaceOrientationPortrait;
}

這樣的話就實現(xiàn)其余頁面支持橫豎屏,需要只支持豎屏的頁面只支持豎屏了,是不是很簡單!

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

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

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