如何将 NavigationController 保持在 subViewController 方向?
我制作了一个 NavigationController 结构。 FirstViewController是RootViewController,SecondViewController是下一个SubViewController。每个ViewController的shouldAutorotateToInterfaceOrientation都是不同的(参考下面的代码)。 FirstViewController 仅适用于纵向。 SecondViewController都支持Portrait和landscapeMode。
在 FirstViewController 中,触摸某个按钮后,调用 PushHandler。接下来的 SecondViewController 是一个被推送的。 在将横向旋转回 FirstViewController 后的 SecondViewController 中,该方向过于横向。
但是,我实现了每个 ViewController 方向不同。但是每个 ViewController 不能独立设置方向。为什么会发生?
我怎样才能让viewcontroller的每个方向都可以独立设置呢?
如果 SecondViewController 改变landscapeMode的方向。我想回到FirstViewController仍然是portraitMode(永远保持portraitState任何东西不受影响)。 如何以编程方式实施?
FirstViewController *rootViewController = [FirstViewController alloc] init];
UINavigationController *MyNavigationController = [UINavigationController alloc] initWithRootViewController:rootViewController]];
//FirstViewController
- (void)pushHandler
{
SecondViewController *subViewController = [SecondViewController alloc] init];
[[self navigationController] pushViewController:subViewController animated:YES];
[subViewController release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
//SecondViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
I have made a NavigationController structure.
FirstViewController is RootViewController, SecondViewController is a next SubViewController. Each ViewController shouldAutorotateToInterfaceOrientation is a different(refer a following code).
FirstViewController is only portrait available. SecondViewController all support Portrait and landscapeMode.
In FirstViewController after sth button touch, call a pushHandler. next SecondViewController is a pushed.
In SecondViewController after rotated landscape back to the FirstViewController, that orientation is too landscape.
but, I implemented each ViewController orientation different. however each ViewController not independently set orientation. why happen?
How can I viewcontroller each orientation can be set independently, to do?
If SecondViewController change the orientation of the landscapeMode. I want back to the FirstViewController still portraitMode(forever hold portraitState Anything not to be affected).
How do I implements programmatically?
FirstViewController *rootViewController = [FirstViewController alloc] init];
UINavigationController *MyNavigationController = [UINavigationController alloc] initWithRootViewController:rootViewController]];
//FirstViewController
- (void)pushHandler
{
SecondViewController *subViewController = [SecondViewController alloc] init];
[[self navigationController] pushViewController:subViewController animated:YES];
[subViewController release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
//SecondViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您对所有
UIViewControllers
使用UINavigationController
,所以您为UINavigationController
设置的任何方向行为都将应用于它的所有子项< /code> 或者换句话说,堆栈上的对象。
将
UINavigationController
视为房屋,将UIViewControllers
视为房间。房子里的所有房间都会以与房子相同的方式旋转。不转动房屋和其他房间就无法转动房间。但一如既往,还是有技巧的。看看我对这个问题的回答 在 xcode 中只有一个视图自动旋转?
Because you use a
UINavigationController
for all yourUIViewControllers
whatever orientation behaviour you will set for theUINavigationController
will be applied to all it'schildren
or in otherwords objects on its stack.Think of a
UINavigationController
as a house andUIViewControllers
as rooms. All the rooms in the house will rotate in the same way the house. There is no way to turn a room without turning the house and other rooms.But as always there are tricks. Look at my answer to this question Only having one view autorotate in xcode?