来自UIModalTransitionStylePartialCurl viewController的presentModalViewController

发布于 2024-12-25 07:27:38 字数 441 浏览 2 评论 0 原文

我有一个通过 UIModalTransitionStylePartialCurl 转换呈现的模式视图。在该模态视图中有一个按钮,我想:

  1. 关闭当前模态视图(向下卷曲),然后
  2. 呈现一个新的模态视图(垂直覆盖)。

然而,当我尝试以下操作时,它只是忽略了卷曲模式视图,但不显示新的视图:

[self dismissModalViewControllerAnimated:YES];
NewView *vc = [[NewView alloc] init];
[self.parentViewController presentModalViewController:vc animated:YES];

我有一种感觉,它与最后一行有关。在 self 上呈现 NewView 也不起作用。我怎样才能做到这一点?

I have a modal view that is presented via UIModalTransitionStylePartialCurl transition. In that modal view there is a button, which I would like to:

  1. dismiss the current modal view (curl down), then
  2. present a new modal view (cover vertical).

However, when I try the following, it simply dismisses the curl modal view but doesn't present the new one:

[self dismissModalViewControllerAnimated:YES];
NewView *vc = [[NewView alloc] init];
[self.parentViewController presentModalViewController:vc animated:YES];

I have a feeling it has to do with that last line. Presenting NewView on self doesn't work either. How can I accomplish this?

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

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

发布评论

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

评论(2

朦胧时间 2025-01-01 07:27:38

您使用的是 iOS 5 吗?

如果是这样,您看到的问题是由于此处记录的更改所致: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController

该链接的重要一点是:

在 iOS 5.0 之前,如果视图没有父视图控制器并且以模态方式呈现,则将返回呈现该视图的视图控制器。现在情况已不再如此。您可以使用presentingViewController属性获取呈现视图控制器。

因此,更改为 self.presentingViewController 可能会解决您的问题,但可能不会。

使用第一个模式中的此代码:

[self dismissModalViewControllerAnimated:YES];
SecondViewController *sec = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.presentingViewController presentModalViewController:sec animated:YES];

您看不到呈现的新视图控制器。

为了得到你想要的东西,你需要使用一个新的(从 iOS5 开始)方法:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

这个方法是presentModalViewController 的推荐替代品。

第一个视图控制器上的自定义方法,类似于:

- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController

该方法既可以关闭当前模态,又可以呈现新模态,如下所示:

- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController {
    [self dismissViewControllerAnimated:YES completion:^{
        [self presentViewController:newViewController animated:YES completion:NULL]; 
    }];
}

使用完成块启动新模态,让您等待旧模态动画结束。因此,在第二个模态视图控制器中,您将在第一个模态视图控制器上调用自定义方法,并让它管理消除/呈现新视图控制器。

Are you using iOS 5?

If so the problem you are seeing is due to a change documented here: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController

The important bit at that link is this:

Prior to iOS 5.0, if a view did not have a parent view controller and was being presented modally, the view controller that was presenting it would be returned. This is no longer the case. You can get the presenting view controller using the presentingViewController property.

So changing to self.presentingViewController may fix your issue, but probably will not.

Using this code from your first modal:

[self dismissModalViewControllerAnimated:YES];
SecondViewController *sec = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.presentingViewController presentModalViewController:sec animated:YES];

You don't see the new view controller presented.

To get what you are after you want to use a new (as of iOS5) method:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

This method is the recommended replacement for presentModalViewController.

And a custom method on your first view controller, something like:

- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController

That method can both dismiss your current modal and present the new one, something like this:

- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController {
    [self dismissViewControllerAnimated:YES completion:^{
        [self presentViewController:newViewController animated:YES completion:NULL]; 
    }];
}

Using the completion block to launch the new modal let's you wait until the old modal has animated out. So in your second modal view controller you would call your custom method on your first modal view controller and let it manage dismissing/presenting the new one.

行雁书 2025-01-01 07:27:38

首先要验证的是 self.parentViewController 是否为零。

NSLog(@"parent == %@", self.parentViewController);

如果它是nil(在我的测试中它是nil),您将需要在该模式视图中传递一个指向您的父级的指针。
之后,您可以

[self.caller performSelector:@selector(launchNewView:) 
                  withObject:nil 
                  afterDelay:1.0];
[self.caller dismissModalViewControllerAnimated:YES];

在此处执行类似的操作 self.caller 是 UIViewController 上以模态呈现之前设置的“父级”。
我不认为这是一个完美的解决方案,但它在我的测试中有效。

The first thing to verify would be if self.parentViewController is nil or not.

NSLog(@"parent == %@", self.parentViewController);

if it's nil (in my test it was nil) you will need to pass a pointer to your parent in that modal view.
And after that you could do something like this

[self.caller performSelector:@selector(launchNewView:) 
                  withObject:nil 
                  afterDelay:1.0];
[self.caller dismissModalViewControllerAnimated:YES];

here self.caller is the "parent" that was set on the UIViewController just before it was presented modally.
I don't find this to be a perfect solution, but it's working in my test.

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