首先停用 UIModalTransitionStylePartialCurl 打开新的 UIVIewController
我有三个 UIViewController:MainViewController、CurledViewController 和 SecondayViewController。
在 MainViewController 上,我在 MainViewController 中有一个 UIButton,它通过以下方式显示 CurledViewController:
curled = [[CurledViewController alloc] init];
[curled setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:curled animated:YES];
从文档中我得知:
使用此转换呈现的模态视图本身会被阻止 呈现任何其他模式视图。
当 CurledViewController 以这种方式显示时,这会阻止我打开 secondaryViewController。我想做的是,在 CurledViewController 中选择 UIButton 时,关闭curl并打开SecondaryViewController(无论是来自CurledViewController还是MainViewController的调用都没关系)。关闭SecondaryViewController后,我希望重新打开CurledViewController。
在附加到 CurledViewController 中 UIButton 的函数中,我尝试了以下操作:
- (void)showSecondary:(UIButton *)sender {
[self.parentViewController dismissModalViewControllerAnimated:YES];
SecondaryViewController *secondaryView = [[SecondaryViewController alloc] initWithNibName:@"Secondary" bundle:Nil];
[self presentModalViewController:secondaryView animated:YES];
...
}
但仍然被告知,
Application tried to present a nested modal view controller while curled
如何以这种方式打开一个新的 UIViewController?
谢谢!
I have three UIViewControllers: MainViewController, CurledViewController and SecondayViewController.
On MainViewController I have one UIButton in the MainViewController that displays the CurledViewController through:
curled = [[CurledViewController alloc] init];
[curled setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:curled animated:YES];
From the documentation I am told:
A modal view presented using this transition is itself prevented from
presenting any additional modal views.
Which prevents me from opening the SecondaryViewController when the CurledViewController is displayed in this way. What I would like to do is, on the selection of a UIButton in CurledViewController, close the curl and open the SecondaryViewController (whether it's a call from CurledViewController or MainViewController doesn't matter). Upon closing SecondaryViewController, I would like CurledViewController to be re-opened.
In the function attached to the UIButton in CurledViewController I have attempted this through:
- (void)showSecondary:(UIButton *)sender {
[self.parentViewController dismissModalViewControllerAnimated:YES];
SecondaryViewController *secondaryView = [[SecondaryViewController alloc] initWithNibName:@"Secondary" bundle:Nil];
[self presentModalViewController:secondaryView animated:YES];
...
}
but am still told,
Application tried to present a nested modal view controller while curled
How do I go about opening a new UIViewController in this fashion?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题是,用于呈现 secondaryViewController 的代码仍在 CurledViewController 中执行。一种替代方法是创建一个 CurledViewControllerDelegate 协议。使 MainViewController 成为 CurledViewController 的委托,并从 showSecondary 调用您的委托方法。
在 CurledViewController 中,您的方法可能如下所示:
在 MainViewController 中,您的委托方法可能如下所示:
编辑
为了在新模态视图控制器的关闭和呈现上保持动画,您将需要引入延迟,以便有足够的时间完成第一个动画。您可以通过使用适当的延迟值调用
performSelector:withObject:afterDelay:
来完成此操作。然而,这是一种容易出错的方法,因为它假设第一个动画始终具有相同的持续时间。正如 Andrew Pouliot 在另一个问题中建议的,您也可以尝试覆盖
viewDidAppear:< /code> 在您的 MainViewController 中,以便它查找一个标志来确定是否应显示 secondaryViewController。这仍然会使用我上面提到的委托方法,但 MainViewController 会有以下差异:
The problem here is that your code for presenting the SecondaryViewController is still executing from the CurledViewController. One alternative approach to try would be to create a CurledViewControllerDelegate protocol. Make MainViewController the delegate of CurledViewController and call your delegate method from showSecondary.
In CurledViewController, your method might look like:
In MainViewController, your delegate method might look like:
Edit
In order to keep the animations on both the dismissal and the presentation of the new modal view controller, you will need to introduce a delay that allows enough time for the first animation to complete. You can do this by invoking
performSelector:withObject:afterDelay:
with an appropriate delay value. This is an error prone approach, however, as it assumes that the first animation will always have the same duration.As Andrew Pouliot suggested in another question, You could also try to override
viewDidAppear:
in your MainViewController, so that it looks for a flag to determine whether a SecondaryViewController should be presented. This would still use the delegate approach I mentioned above, but MainViewController would have the following differences: