@IT·互联网程序员

iOS指定页面默认横屏,自由切换

2017-04-01  本文已影响0人  shyizne

闲话不多说先上效果图

这里面用的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;

}

以上就是横屏设置了,代码不到位的,请多包涵。

上一篇下一篇

猜你喜欢

热点阅读