- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个导航 Controller ,它有几个 View Controller 。我需要支持所有 View Controller 的所有方向,除了一个只支持横向的特殊 View Controller 。这个特殊的 View Controller 出现在导航堆栈的中间。我做了很多研究,但找不到任何好的解决方案。以下是我已阅读和尝试过的链接。
How to rotate screen to landscape?
How to autorotate from portrait to landscape mode? iPhone - allow landscape orientation on just one viewcontroller http://goodliffe.blogspot.com/2009/12/iphone-forcing-uiview-to-reorientate.html
接下来我将尝试用 presentModalViewController
替换导航 Controller 以显示特殊 View Controller 。然后我将在特殊 View Controller 中创建一个新的导航 View Controller 来推送后续的 View Controller 。
如果有人有更好的想法,请告诉我。非常感谢!
更新:我已经成功地使用了我上面描述的方法:将 pushViewController
替换为 presentModalViewController
并创建一个新的导航 Controller 。
最佳答案
每个推送到导航 Controller 堆栈上的 View Controller 都必须支持相同的方向。这意味着不可能让一些 View Controller 只支持纵向,而另一些只支持横向。换句话说,同一个导航 Controller 堆栈上的所有 View Controller 都应该在委托(delegate)中返回相同的值:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
但是有一个简单的解决方案!这是一个从肖像到风景的例子。以下是执行此操作的步骤,下面是支持它的代码。
UINavigationController
的新实例,将“假” View Controller 的实例添加为根,将横向 View Controller 的实例添加为第二个 View Controller UINavigationController
实例作为父 View Controller 的模态呈现首先,使用以下代码创建一个新的 View Controller (FakeRootViewController):
@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));
}
这里是呈现您希望在横向模式下显示的 View Controller 的代码:
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];
记住 landscapeViewController 也应该有这个实现:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationIsLandscape(interfaceOrientation));
}
关于ios - 在 UINavigationController 中仅支持一个 View 的横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5023487/
我有几个由导航 Controller 控制的 View Controller 。 例如,viewController A 和 viewController B 都可以将 viewController
目前我在单独的 Storyboard中有一个导航 Controller ,它使用退出按钮。这个退出按钮应该返回到 rootViewController(那是在 mainstoryboard 中)这是一
我目前正在将我的应用程序迁移到 iOS 7 上,并且在新的导航 Controller /栏管理上已经卡了好几个小时了。 之前,当我们有导航 Controller 时,我们有这样的代码片段: UINav
我环顾四周,终究找不到用滑动手势替换 backbarbuttonitem 的方法。我想向左滑动并让应用恢复到之前的 View Controller 。澄清一下,我正在使用 UINavigationCo
我环顾四周,终究找不到用滑动手势替换 backbarbuttonitem 的方法。我想向左滑动并让应用恢复到之前的 View Controller 。澄清一下,我正在使用 UINavigationCo
我使用 320*44 图像自定义 NavigationBar backgroundImage。因此状态栏为黑色。这就是我想要的。但是,当我呈现此 navigationController 时,如您所知
我正面临以下代码的崩溃。场景是 这是我的应用委托(delegate)方法,我在其中使用 UINavigationController 加载 RTC_HomeVC。 - (BOOL)applicatio
目前我有一个使用 uinavigationcontroller 但仅在 Root View 中隐藏导航栏的应用程序,我想在某些应用程序中将此应用程序用作外部库并将整个应用程序作为一个菜单项推送。 但是
我有两个 View Controller ,ViewControllerA 和 ViewControllerB,嵌入在 UINavigationController 中。 ViewController
iOS 7 采用了一种新手势,在屏幕上从左到右滑 Action 为 UINavigationController 中返回按钮的快捷方式。 我的应用似乎没有免费采用这种行为。我需要做什么才能使这个手势可
我已经在这上面花了几个小时,但无法让它工作。希望有人能帮助我。 我有一个 UIPageViewController,当我在应用程序启动时将它添加到我的默认 View 时,它可以完美地工作。这就是我所做
我想为我的 UIToolbar 使用我自己的背景。 要使用 UINavigationBar 做到这一点,我刚刚使用了这个类别并覆盖了 drawRect 方法: @implementation
我正在展示一个 UINavigationController模态地,从 iOS 应用程序扩展中: UINavigationController *nav = [[UINavigationControl
我读到在 iOS 应用程序中有这样的结构是不好的。但是,如果应用程序有很多 UINavigationController 和 UITabBarController 怎么办?但是一个UINavigati
我们在 UISplitViewController 应用程序中有我们需要的特定行为。我们有以下 3 个 View 的层次结构 FormOneViewController - 在 MasterView
我试图将一个简单的 UIToolbar 放在模态呈现的 UINavigationController 的底部。在这个示例中,它应该包含两个按钮“取消”和“某事”。 ... UINavigationCo
我有一个 UITabBarController,其中包含一些选项卡。其中一个选项卡具有 UINavigationController 和 UITableViewController 作为 Root V
我的应用程序的整个导航系统都是围绕导航 Controller 构建的。我所有的风险投资公司都被插入和推出。我有一个从左侧出来的菜单系统“抽屉”,它是我的自定义导航 Controller 的一部分。在菜
我有一个 UINavagationController (NC),它显示“Items”数组的多个 UIViewController (VC) View ,并且我有一个 UINavigationCont
在我的 UISplitViewController ,主 View 是UINavigationController包含 UITableViewController .有时,当用户选择表中的项目时,我不
我是一名优秀的程序员,十分优秀!