IOS豎屏應用單個頁面橫屏的解決辦法


     昨天朋友問我,怎么實現在豎屏的應用里,顯示一個橫屏的應用,由於也沒做過

就說不知道了,但是我覺得會有這樣的API ,因為我手機里就安裝有這種類型的軟件

今天早上起來,就想做一個Demo出來,慣例的是查找資料,測試是否可以使用,但是

查找了都寫的不是很清楚,很容易造成沒法實現想要的效果,所以想重新寫過一個

希望能幫到有這個需求的朋友。(這個沒什么經驗,的是照着網上的資料拼湊起來,

如果有錯誤,請見諒,有更好的辦法也可以告訴我)

 

實現的效果:

        頁面大部分是豎屏,個別頁面可以旋轉手機時頁面變為橫屏(其實朋友的需求是,進入

這個頁面就是橫屏的,不知道怎么弄)。

 

實現步驟:

  1.使應用可以橫屏,新創建的默認就可以

 

2.在跟視圖里實現以下的方法(導航控制器和TabBar控制器的可以)

 

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}

 

3.在不需要橫屏的視圖控制器里面實現以下方法

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait ;
}
- (BOOL)shouldAutorotate
{
    return NO;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

 4,需要橫屏的頁面不需要其他的處理就可以了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM