iPad Modal View 旋转parentViewController View
当应用程序处于横向模式(我计划强制)时,显示模式视图会导致父视图旋转到纵向模式。如果我将 shouldAutoRotateToInterfaceOrientation 的返回值设置为 NO,则父级不会旋转,但模式会从侧面滑入并横向显示。下面是显示模式的代码。
- (IBAction)loadExistingGame:(id)sender {
SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
savedGames.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:savedGames animated:YES];
[savedGames release];
根据请求,
这里是 SavedGamesTableViewController 的 shouldAutoRotate 方法的内容
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
When the application is in landscape mode (which I plan to force), displaying a modal view causes the parent view to rotate to portrait mode. If I set the return value of shouldAutoRotateToInterfaceOrientation to NO, the parent does not rotate, however the modal then slides in from the side and displays sideways. Below is the code that reveals the modal.
- (IBAction)loadExistingGame:(id)sender {
SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
savedGames.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:savedGames animated:YES];
[savedGames release];
}
As per request here is the contents of the shouldAutoRotate method of the SavedGamesTableViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我知道需要做什么来修复它。包含可能方向列表的 plist 文件需要限制为单个横向视图。仅当方向与 plist 文件中的唯一方向匹配时,模态表视图的父级才需要 shouldAutoRotateToInterfaceOrientation 方法返回 YES。
。
对于相同的方法,模态视图控制器应该返回 NO
Ok I figured out what needed to be done to fix it. The plist file that contains a list of the possible orientations needs to be limited to a single landscape view. The parent to the modal table view needs to have the shouldAutoRotateToInterfaceOrientation method return YES only if the orientation matches the only orientation in the plist file.
}
the modal viewcontroller should return NO for the same method.
基于
和
所以你所说的是父视图控制器尚未设置为强制仅使用横向方向,当你显示设置为允许所有方向的模态视图时,你想知道为什么你的父视图旋转为纵向当您将设备旋转到纵向时?我不明白你的问题...你不是说父视图控制器当前设置为允许旋转到纵向吗?这种行为不正是应该发生的吗?
Based on
and
So what you're saying is that the parent view controller is not yet set to force only using landscape orientation, and when you show a modal view that is set to allow all orientations, you're wondering why your parent view rotates to portrait when you rotate the device to portrait? I don't understand your question... aren't you saying that parent view controller is currently set to allow rotation to portrait? Isn't this behaviour exactly what should happen?
在调出模式邮件视图时,我遇到了类似的问题。强制旋转对我来说不起作用,但在应用程序的主视图控制器而不是子视图控制器上调用presentModalViewController解决了问题。
I had a similar problem when bringing up a modal mail view. Forcing the rotation didn't work for me, but calling presentModalViewController on the application's main view controller rather than a child view controller solved the issue.
我也看到了同样的行为;就我而言,问题是我已经实现了 shouldAutorotateToInterfaceOrientation 来为父视图控制器无条件返回 YES,但对于所呈现的模态视图控制器则不返回 YES。所以我怀疑 Shaggy Frog 的评论是关键:无论你是否想要强制横向模式,你都需要确保两个视图控制器的 shouldAutorotateToInterfaceOrientation 实现一致,否则就会出现奇怪的情况。
I was seeing the same behavior; in my case the problem was I had implemented shouldAutorotateToInterfaceOrientation to return YES unconditionally for the parent view controller but NOT for the presented modal view controller. So I suspect Shaggy Frog's comment is the key: whether you want to force landscape mode or not, you need to make sure that the two view controllers' shouldAutorotateToInterfaceOrientation implementations agree or weirdness will ensue.
在 iOS6 上,我使用 UINavigationController。
在 iOS6 之前的版本中,我对 UINavigationController 进行了子类化,如下所示:
On iOS6 I use a UINavigationController.
On pre-iOS6 I subclass UINavigationController, like this: