你将如何实现[UIViewController presentModalViewController]?

时间:2022-12-09 11:59:02

I have to customize the transition between 2 different UIViewController and for that I would like to re-implement [UIViewController presentModalViewController...]. What is inside this function? How does it work? What does it do?

我必须自定义2个不同的UIViewController之间的转换,为此我想重新实现[UIViewController presentModalViewController ...]。这个功能里面有什么?它是如何工作的?它有什么作用?

Thanks a lot, Vance

非常感谢,万斯

2 个解决方案

#1


1  

The -[UIViewController presentModalViewController:animated:] do allot of magic behind the scenes.

- [UIViewController presentModalViewController:animated:]在幕后分配魔法。

For my app Tweet Note I wanted to present modal view controllers by animating the new view from the backside of a view in a shelf. More or less what iBooks does. I tried to override the default implementation but ended up doing it in a multi step solution that works without ugly hacks and caveats:

对于我的应用程序Tweet注意我想通过从架子中的视图的背面动画新视图来呈现模态视图控制器。或多或少是iBooks所做的。我试图覆盖默认的实现,但最终在多步骤解决方案中执行它,没有丑陋的黑客和警告:

  1. Instantiate the new view controller.
  2. 实例化新的视图控制器。
  3. Apply the transform to the new view controller's managed view, so that it starts in it's initial location.¨
  4. 将变换应用于新视图控制器的托管视图,以便从它的初始位置开始
  5. Start animating the view into untransformed "normal" position.
  6. 开始将视图设置为未转换的“正常”位置。
  7. Wait for animation to finish, and do as a unit:
    • Remove the view you just animated from screen.
    • 从屏幕中删除刚刚动画的视图。
    • Call [self presentModalViewController:vc animated:NO].
    • 调用[self presentModalViewController:vc animated:NO]。
  8. 等待动画完成,并作为一个整体执行:删除刚从屏幕设置动画的视图。调用[self presentModalViewController:vc animated:NO]。

That last step is important! After your transition animation completes present the modal view controller as normal but without animation, and will appear to the user just as if you did a proper animated presentation.

最后一步很重要!转换动画完成后,模态视图控制器正常但没有动画,并且将向用户显示,就像您进行了正确的动画演示一样。

Dismissing with your custom transition is more or less doing the same thing but in reverse order.

使用自定义转换消除或多或少做同样的事情,但顺序相反。

#2


-1  

There are a variety of transitions available. Do none of them meet your needs? See this post for more.

有各种各样的过渡。它们都不符合您的需求吗?有关更多信息,请参阅此帖

#1


1  

The -[UIViewController presentModalViewController:animated:] do allot of magic behind the scenes.

- [UIViewController presentModalViewController:animated:]在幕后分配魔法。

For my app Tweet Note I wanted to present modal view controllers by animating the new view from the backside of a view in a shelf. More or less what iBooks does. I tried to override the default implementation but ended up doing it in a multi step solution that works without ugly hacks and caveats:

对于我的应用程序Tweet注意我想通过从架子中的视图的背面动画新视图来呈现模态视图控制器。或多或少是iBooks所做的。我试图覆盖默认的实现,但最终在多步骤解决方案中执行它,没有丑陋的黑客和警告:

  1. Instantiate the new view controller.
  2. 实例化新的视图控制器。
  3. Apply the transform to the new view controller's managed view, so that it starts in it's initial location.¨
  4. 将变换应用于新视图控制器的托管视图,以便从它的初始位置开始
  5. Start animating the view into untransformed "normal" position.
  6. 开始将视图设置为未转换的“正常”位置。
  7. Wait for animation to finish, and do as a unit:
    • Remove the view you just animated from screen.
    • 从屏幕中删除刚刚动画的视图。
    • Call [self presentModalViewController:vc animated:NO].
    • 调用[self presentModalViewController:vc animated:NO]。
  8. 等待动画完成,并作为一个整体执行:删除刚从屏幕设置动画的视图。调用[self presentModalViewController:vc animated:NO]。

That last step is important! After your transition animation completes present the modal view controller as normal but without animation, and will appear to the user just as if you did a proper animated presentation.

最后一步很重要!转换动画完成后,模态视图控制器正常但没有动画,并且将向用户显示,就像您进行了正确的动画演示一样。

Dismissing with your custom transition is more or less doing the same thing but in reverse order.

使用自定义转换消除或多或少做同样的事情,但顺序相反。

#2


-1  

There are a variety of transitions available. Do none of them meet your needs? See this post for more.

有各种各样的过渡。它们都不符合您的需求吗?有关更多信息,请参阅此帖