iPad Modal View 旋转parentViewController View

发布于 2024-09-24 10:15:44 字数 778 浏览 4 评论 0原文

当应用程序处于横向模式(我计划强制)时,显示模式视图会导致父视图旋转到纵向模式。如果我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

与酒说心事 2024-10-01 10:15:44

好吧,我知道需要做什么来修复它。包含可能方向列表的 plist 文件需要限制为单个横向视图。仅当方向与 plist 文件中的唯一方向匹配时,模态表视图的父级才需要 shouldAutoRotateToInterfaceOrientation 方法返回 YES。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return interfaceOrientation = UIInterfaceOrientationLandscapeRight;

对于相同的方法,模态视图控制器应该返回 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.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return interfaceOrientation = UIInterfaceOrientationLandscapeRight;

}

the modal viewcontroller should return NO for the same method.

烟燃烟灭 2024-10-01 10:15:44

基于

当应用程序处于横向状态时
模式(我计划强制),
显示模态视图会导致
父视图旋转为纵向
模式。

根据要求,这里的内容是
的shouldAutoRotate方法
SavedGamesTableViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}

所以你所说的是父视图控制器尚未设置为强制仅使用横向方向,当你显示设置为允许所有方向的模态视图时,你想知道为什么你的父视图旋转为纵向当您将设备旋转到纵向时?我不明白你的问题...你不是说父视图控制器当前设置为允许旋转到纵向吗?这种行为不正是应该发生的吗?

Based on

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.

and

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;
}

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?

童话里做英雄 2024-10-01 10:15:44

在调出模式邮件视图时,我遇到了类似的问题。强制旋转对我来说不起作用,但在应用程序的主视图控制器而不是子视图控制器上调用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.

無處可尋 2024-10-01 10:15:44

我也看到了同样的行为;就我而言,问题是我已经实现了 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.

仲春光 2024-10-01 10:15:44
UIViewController *vc = /* create view controller */;
UINavigationController *nc = nil;
if (IOS_VERSION_LESS_THAN_6_0) {
    nc = [[MyCustomNavigationControllerSupportingAllOrientations alloc] initWithRootViewController:vc];
} else {
    nc = [[UINavigationController alloc] initWithRootViewController:vc];
}
[self.navigationController presentModalViewController:nc animated:YES];

在 iOS6 上,我使用 UINavigationController。

在 iOS6 之前的版本中,我对 UINavigationController 进行了子类化,如下所示:

@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController
@end

@implementation MyCustomNavigationControllerSupportingAllOrientations
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end
UIViewController *vc = /* create view controller */;
UINavigationController *nc = nil;
if (IOS_VERSION_LESS_THAN_6_0) {
    nc = [[MyCustomNavigationControllerSupportingAllOrientations alloc] initWithRootViewController:vc];
} else {
    nc = [[UINavigationController alloc] initWithRootViewController:vc];
}
[self.navigationController presentModalViewController:nc animated:YES];

On iOS6 I use a UINavigationController.

On pre-iOS6 I subclass UINavigationController, like this:

@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController
@end

@implementation MyCustomNavigationControllerSupportingAllOrientations
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文