竖屏模式代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
同样的,横屏模式一样的代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft); } -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeLeft; }
Every view controller pushed onto the navigation controllers stack have to support the same orientations. This means that it is not possible to have some view controllers only supporting portrait and others only supporting landscape. In other words all view controllers on the same navigation controller stack should return the same in the delegate:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
But there is a simple solution to this! Here is an example for going from portrait to landscape. Here is the steps to do it and below is code to support it.
1. Create a ‘fake’ view controller that will be root in a sub navigation controller.
This view controller should support landscape.
2. Create a new instance of a UINavigationController, add an instance of the ‘fake’ view controller as root and an instance of your landscape view controller as second view controller
3. Present the UINavigationController instance as modal from the parent view controller
First, create a new view controller (FakeRootViewController) with this code:
interface FakeRootViewController : UIViewController @property (strong, nonatomic) UINavigationController* parentNavigationController; @end @implementation FaceRootViewController @synthesize parentNavigationController; // viewWillAppear is called when we touch the back button on the navigation bar (void)viewWillAppear:(BOOL)animated { // Remove our self from modal view though the parent view controller [parentNavigationController dismissModalViewControllerAnimated:YES]; } (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationIsLandscape(interfaceOrientation)); }
Here is the code to present the view controller that you wish to show in landscape mode:
FakeRootViewController* fakeRootViewController = [[FakeRootViewController alloc] init];[fakeRootViewController.navigationItem setBackBarButtonItem:backButton]; // Set back button // The parent navigation controller is the one containing the view controllers in portrait mode. fakeRootViewController.parentNavigationController = parentNavigationController; UINavigationController* subNavigationController = // Initialize this the same way you have initialized your parent navigation controller. UIViewController* landscapeViewController = // Initialize the landscape view controller [subNavigationController setViewControllers: [NSArray arrayWithObjects:fakeRootViewController, landscapeViewController, nil] animated:NO]; [_navigationController presentModalViewController:subNavigationController animated:YES];
Remember that the landscapeViewController should also have this implementation:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationIsLandscape(interfaceOrientation)); }
相关推荐
IOS7 UINavigationController滑动Demo,解决了在push后的页面可以滑动返回的问题。
iOS 使用UINavigationController 进行页面跳转 http://blog.csdn.net/liuyan20092009/article/details/52233769
导航控制器(UINavigationController)用来管理一系列显示层次型信息的场景。一般而言,逐步显示更详细的信息。 导航控制器 -- 用户在场景之间切换时,导航控制器依次将视图控制器压入(push)堆栈中,且当前场景的...
iOS 自定义UINavigationController和UITabBarController
iOS UINavigationController自定义,push动画效果
UINavigation 代码 IOS 导航栏 Demo
IOS 导航 UINavigationController,说明了setBackBarButtonItem,setRightBarButtonItem,setLeftBarButtonItem,setTitleView
很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。
SwipetoFinishActivity, 像iOS的UINavigationController那样可以对Activity进行滑动返回操作
ViewController中[self setTtile]与[self.navigationItem setTitle]的区别 - http://blog.csdn.net/moon_prince2013/article/details/49079201 [[ViewController alloc]init]与[ViewController alloc]...
我们写iOS项目的时候,基本都是一个UINavigationController套一个UITabBarController的形式,就是上面一个导航栏,下面几个按钮的工具条的形式。我写了几个应用,发现如果每次都重新写的话完全就是浪费精力和时间,...
iOS 7 中新增加的UINavigationController 推送方法
iOS中present出一个透明导航控制器NavigationController 的方法+毛玻璃效果
效果参考 App:腾讯新闻、百度音乐等等 GitHub:https://github.com/LeoiOS/LCNavigationController
主要为大家详细介绍了iOS自定义导航控制器UINavigationController,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
上传的demo关于UINavigationController中back按钮的重写方法, UINavigationController的back按妞本身是没有监听方法的,但是我们通过添加类目可以使back按钮具有监听的作用.让我们能在UINavigationController触发返回...
#MZNavTab MZNavTab 是一个 iOS 库,它可以帮助你结合 UITabBar 和 UINavigationController。目的MZNavTab 是一个灵活方便的 iOS 库,可以帮助您结合 UITabBarController(实际上是 UITabBar,或者只是一个像标签栏...
* 从iOS7开始,系统为UINavigationController提供了一个interactivePopGestureRecognizer用于右滑返回(pop),但是,如果自定了返回按钮或者隐藏了navigationBar,该手势就失效了。 ## 原因 * 自定义返回按钮或者隐藏...
iOS的SDK中提供很多原生ViewController,以支持标准的用户界面,例如表视图控制器(UITableViewController)、导航控制器(UINavigationController)、标签栏控制器(UITabbarController)和iPad专有的...
在AppDelegate.m 创建一个导航栏 ViewController *nc=[[ViewController alloc]init]; UINavigationController *vc=[[UINavigationController alloc]initWithRootViewController:nc]; self.window....