在 UINavigationController 中转换为纵向旋转
我有一种情况,需要将仅纵向模式视图推送到导航控制器中,该导航控制器将横向模式视图作为其当前视图。
虽然我已经重新实现了
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
,但它仍然在横向模式下推动视图。我也尝试过以下方法,但即使这样也不起作用。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
我尝试查看其他相关问题,但没有找到任何东西。
知道我该如何解决这个问题吗?
谢谢!
I have a case where a portrait only mode view needs to be pushed into a navigation controller which has a landscape mode view as its current view.
Although I have reimplemented
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
but it is still pushing the view in landscape mode. I have also tried the following way, but even this is not working.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
I tried looking into other related questions but did not find anything.
Any idea how I can solve this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择是只使用
模态视图控制器
,它会强制视图处于纵向,无论设备方向如何。如果您想在其周围包装一个导航控制器以保持样式一致,请查看 Apple 的 核心数据配方示例,了解当您添加新配方时它们如何执行此操作。
Your best bet is to just use a
modal view controller
instead which forces the view to be in portrait regardless of device orientation.If you want to wrap a navigation controller around it to keep styling consistent, look at Apple's Core Data Recipes example for how they do this when you add a new recipe.