iOS指定頁(yè)面默認(rèn)橫屏,自由切換

閑話不多說(shuō)先上效果圖

這里面用的present?頁(yè)面切換

1.先在AppDelegate中重寫-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window方法,交代進(jìn)入的BaseNavi,以及RootView。代碼如下

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

// Override point for customization after application launch.

self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

[self.windowsetBackgroundColor:[UIColorwhiteColor]];

UIStoryboard*storyBoard = [UIStoryboardstoryboardWithName:@"Main"bundle:[NSBundlemainBundle]];

ViewController*vc = [storyBoardinstantiateViewControllerWithIdentifier:@"ViewController"];

BaseViewController* nav = [[BaseViewControlleralloc]initWithRootViewController:vc];

[self.windowsetRootViewController:nav];

[self.windowmakeKeyAndVisible];

returnYES;

}

-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{

returnUIInterfaceOrientationMaskAll;

}

2.創(chuàng)建一個(gè)BaseNavi,就是上一步用到的。方法寫上

- (BOOL)shouldAutorotate

{

return[self.topViewControllershouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return[self.topViewControllersupportedInterfaceOrientations];

}

3.在第一個(gè)頁(yè)面寫上,支持旋轉(zhuǎn) 但是這個(gè)頁(yè)面只支持豎屏,代碼:

//支持旋轉(zhuǎn)

-(BOOL)shouldAutorotate{

returnYES;

}

//支持的方向因?yàn)榻缑鍭我們只需要支持豎屏

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskPortrait;

}

4.第二個(gè)頁(yè)面我們寫上,我們所需要的橫屏效果,代碼:

//支持旋轉(zhuǎn)

-(BOOL)shouldAutorotate{

returnYES;

}

//

//支持的方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskLandscapeLeft;

}

//一開(kāi)始的方向很重要

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

returnUIInterfaceOrientationLandscapeLeft;

}

以上就是橫屏設(shè)置了,代碼不到位的,請(qǐng)多包涵。

最后編輯于
?著作權(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)容