简体   繁体   English

在过渡期间对子视图控制器的视图进行动画处理

[英]Animating Child View Controller's views during transition

I have a Master custom container view controller, whose purpose is to swap between two different view controllers that each manage a form with text fields. 我有一个Master自定义容器视图控制器,其目的是在两个不同的视图控制器之间交换,每个视图控制器管理带有文本字段的表单。 We'll call these FormVC1 and FormVC2. 我们将它们称为FormVC1和FormVC2。 Both of these controllers's views are managed by a XIB. 这两个控制器的视图均由XIB管理。

I can successfully swap between FormVC1 and FormVC2 using: 我可以使用以下方法在FormVC1和FormVC2之间成功交换:

transitionFromViewController:toViewController:duration:options:animations:completion: while passing UIViewAnimationOptionTransitionCrossDissolve for the options argument. transitionFromViewController:toViewController:duration:options:animations:completion:同时将UIViewAnimationOptionTransitionCrossDissolve传递给options参数。

Now I want to sweeten the transition a little, and when FormVC1 is being dismissed, I want the individual text fields to fly off to the left (one at a time), and when FormVC2 is being presented, I want the individual text fields to fly in from the right, one at a time. 现在,我想稍微简化一下过渡,当关闭FormVC1时,我希望各个文本字段向左飞(一次一个),而当呈现FormVC2时,我希望各个文本字段向左飞。从右边一次飞进来。

I'm a little confused as to how to set this all up, and where exactly to place the specific text field animation code. 我对如何进行全部设置以及将特定文本字段动画代码准确放置在何处感到困惑。 Do I put that in the animation block within Master? 我可以将它放在Master的动画块中吗? Do I put it in each FormVC's appearance callbacks? 是否将其放在每个FormVC的外观回调中?

You have a few options, so pick the one that works best for you: 您有几种选择,因此请选择最适合您的一种:

1) Make the container view controller contain a scrollview, with scrolling disabled, and scrollbars disabled. 1)使容器视图控制器包含一个滚动视图,其中滚动被禁用,滚动条被禁用。 Set the two form vc's as child vc's of the container, and add the views into the scrollview next to each other, so only one is visible. 将这两种形式的vc设置为容器的子vc,并将视图彼此相邻地添加到滚动视图中,以便仅一个可见。 At the appropriate time, show the next form by setting the content offset of the scrollview with animated set to YES. 在适当的时候,通过将带有动画设置的“滚动视图”的内容偏移设置为“是”来显示下一个表单。

2) Even better (more easily extendible to add arbitrary number of forms), use a UICollectionView instead of a basic scrollview, set it to use the horizontal linear layout, make a custom cell to hold your form vc class (disable scrolling and scrollbars), then to show the next form, scrollToItemAtIndexPath:: should do the trick. 2)更好(更容易扩展以添加任意数量的窗体),使用UICollectionView而不是基本的scrollview,将其设置为使用水平线性布局,创建一个自定义单元格来保存窗体vc类(禁用滚动和滚动条) ,然后显示下一个表单,scrollToItemAtIndexPath ::应该可以解决问题。

3) Most basic, maybe good enough: Make your container a navigation controller and just push the form vc with the default transition. 3)最基本,也许足够好:将您的容器设置为导航控制器,并使用默认转换将vc形式推送。

All these solutions assume your form vc's are only the controls you want animated and the main view has a transparent background. 所有这些解决方案都假定您的窗体vc只是要动画的控件,并且主视图具有透明的背景。

In the animations block of transitionFromViewController:toViewController:… change the frames of the elements that you want to be animated. transitionFromViewController:toViewController:…animations块中,更改要动画的元素的帧。 To make it fly off to the left, subtract something like 200 from the frame.origin.x . 为了使其向左飞,请从frame.origin.x减去200 frame.origin.x To make them fly in from the right, start at a high x value (maybe 500) and animate it to the center. 要使它们从右侧飞入,请从较高的x值(可能为500)开始,并将其设置为中心的动画。

To animate them sequentially, you could use different x values for each element. 要对它们进行顺序动画处理,可以为每个元素使用不同的x值。 For something more complex, use animateWithDuration:delay:options:animations:completion: and set up the next animation in the former's completion block. 对于更复杂的内容,请使用animateWithDuration:delay:options:animations:completion:并在前者的completion块中设置下一个动画。 You'd use that instead of transitionFromViewController:toViewController:… . 您将使用它而不是transitionFromViewController:toViewController:…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM