关闭 iPad 模态视图会弄乱 UISplitView 面板

发布于 2024-09-16 14:29:55 字数 1637 浏览 8 评论 0原文

前提非常简单:我想在使用 UISplitViewController 的 iPad 应用程序中显示模式视图。

视图层次结构很简单:

                                              /- TableViewController1
                     /- root:TabBarController -- TableViewController2
SplitViewController -
                     \- detail:CustomViewController

当我单击 TableViewController1 中的一个表格单元格时,我打开一个模态视图:

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip {
  UIViewController *vc = [[MyModalClass alloc] init];
  UINavigationController *nc = [[UINavigationController alloc]
                                initWithRootViewController:vc];
  nc.modalPresentationStyle = UIModalPresentationFormSheet;
  nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:nc animated:true];
  [nc release];
  [vc release];
}

这工作得很好:视图出现。当我试图以横向以外的任何方向消除它时,问题就开始了。

在 ModalViewController 中,导航栏中的 UITabBarButton 触发以下方法:

- (void) closeButtonInNavBarWasClicked:(id)sender {
  [self dismissModalViewControllerAnimated:true];
}

这就是问题开始的地方。

当调用此代码时,模式视图消失,但是:TabBarController(分割视图的根视图)突然旋转并调整大小。内容突然横向倾斜,并部分覆盖了详细信息视图。详细信息视图的大小并未调整得更小,它只是部分地被根视图覆盖。

不会出现此问题的唯一情况是当应用程序处于纵向模式时点击 TableViewController1 单元格时。尽管根视图位于弹出窗口中(这可能是错误的充足来源),但一切正常。

我已经尝试过一些事情,但没有成功:

  • 转储选项卡栏,仅将 TableViewController1 显示为分割视图的根控制器
  • 创建委托协议,以便父 TableViewController1 关闭模态视图而不是 MyModalClass 视图本身。
  • 在 TableViewController1.splitViewController 上呈现/关闭模态视图实际上会让事情变得更糟:视图甚至不会出现。
  • 牺牲几只山羊也无济于事。

我非常感谢有关此问题的任何意见。

The premise is remarkably simple: I want to display a modal view in an iPad app that uses a UISplitViewController.

The view hierarchy is straight-forward:

                                              /- TableViewController1
                     /- root:TabBarController -- TableViewController2
SplitViewController -
                     \- detail:CustomViewController

When I click on one of the table cells in TableViewController1, I open a modal view:

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip {
  UIViewController *vc = [[MyModalClass alloc] init];
  UINavigationController *nc = [[UINavigationController alloc]
                                initWithRootViewController:vc];
  nc.modalPresentationStyle = UIModalPresentationFormSheet;
  nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:nc animated:true];
  [nc release];
  [vc release];
}

This works just fine: the view appears. The problems start when I try to dismiss it in any orientation other than landscape.

In ModalViewController, the following method is triggered by a UITabBarButton in the navigation bar:

- (void) closeButtonInNavBarWasClicked:(id)sender {
  [self dismissModalViewControllerAnimated:true];
}

And THIS is where the problems start.

When this code is called, the modal view disappears, BUT: the TabBarController (the split view's root view) is suddenly rotated and resized. The content is suddenly sideways, and partially covers the details view. The details view isn't resized to be smaller, it's just partially covered by the root view.

The only situation where this problem doesn't appear is when I tap on the TableViewController1 cell when the app is in portrait mode. Despite the root view being in a popover (which could be an ample source of bugs), everything works fine.

Some things I have already tried, with no success:

  • Dump the tab bar, just display TableViewController1 as the root controller of the split view
  • Create a delegate protocol so that the parent TableViewController1 dismisses the modal view rather than the MyModalClass view itself.
  • Presenting/dismissing the modal view on TableViewController1.splitViewController actually makes things worse: the view doesn't even appear.
  • Sacrificing several goats also did not help.

I would hugely appreciate any input on this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

傻比既视感 2024-09-23 14:29:55

我对自己的问题有一个答案:我使用 Instruments 系统地消除了我的应用程序中的所有内存泄漏。一旦我这样做了,问题就消失了。

I have a sort-of-answer to my own question: I used Instruments to systematically eliminate all memory leaks in my app. Once I had done that, the problem vanished.

甜中书 2024-09-23 14:29:55

我遇到了和你一样的问题,我通过以编程方式暂时强制旋转我的呈现视图控制器(一旦返回到它)来解决它,在它的 viewDidAppear 方法中进行任意旋转。当然没有动画。然后将其旋转回所需的方向(我在旋转之前保存了该方向)。

因此,如果 vc1 以模态方式显示 vc2,并且用户旋转 vc2,我将根据 vc2 的当前方向设置 vc1 的方向,方法是调用:
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; //存储vc2的当前方向(模态视图)
[vc1 willRotateToInterfaceOrientation:currentOrientation 持续时间:0];

然后我解雇 vc2 并在 vc1 的 viewWillAppear 中执行以下操作:

-(void) viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

/* Store wanted orientation */
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; 

/* rotate to some arbitrary orientation, this solves the bug. */
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO]; 

[[UIDevice currentDevice] setOrientation:currentOrientation animated:NO]; //restore wanted orientation.

}

I had the same problem as you, I solved it by programatically temporarily force rotate my presenting viewController (once returned to it), in its viewDidAppear method to some arbitrary rotation. Of course without animation. And then rotated it back to the wanted orientation (which I saved in prior to the rotation).

So if vc1 displays vc2 modally, and the user rotates vc2 I set the orientation of vc1 according to current orientation of vc2 by calling:
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; //store current orientation of vc2 (modal view)
[vc1 willRotateToInterfaceOrientation:currentOrientation duration:0];

Then I dissmiss vc2 and in viewWillAppear of vc1 I do this:

-(void) viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

/* Store wanted orientation */
UIInterfaceOrientation currentOrientation = self.interfaceOrientation; 

/* rotate to some arbitrary orientation, this solves the bug. */
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO]; 

[[UIDevice currentDevice] setOrientation:currentOrientation animated:NO]; //restore wanted orientation.

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文