iOS指定頁面默認橫屏,自由切換

閑話不多說先上效果圖

這里面用的present?頁面切換

1.先在AppDelegate中重寫-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window方法,交代進入的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.創建一個BaseNavi,就是上一步用到的。方法寫上

- (BOOL)shouldAutorotate

{

return[self.topViewControllershouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return[self.topViewControllersupportedInterfaceOrientations];

}

3.在第一個頁面寫上,支持旋轉 但是這個頁面只支持豎屏,代碼:

//支持旋轉

-(BOOL)shouldAutorotate{

returnYES;

}

//支持的方向因為界面A我們只需要支持豎屏

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskPortrait;

}

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

//支持旋轉

-(BOOL)shouldAutorotate{

returnYES;

}

//

//支持的方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskLandscapeLeft;

}

//一開始的方向很重要

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

returnUIInterfaceOrientationLandscapeLeft;

}

以上就是橫屏設置了,代碼不到位的,請多包涵。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容