简体   繁体   English

如何在不将视图设置为nil的情况下进行水平翻转动画?

[英]How to do a horizontal flip animation without setting views to nil?

I am doing the "standard" flip between a map and a list view inside a UIViewController with navbar on top, there is a button there that toggles between map showing and list. 我正在UIViewController内的地图和列表视图之间进行“标准”翻转,导航栏在顶部,导航按钮在地图显示和列表之间切换。 I am performing the transition with this method: 我正在使用此方法执行转换:

    [UIView transitionFromView:self.tableView
                        toView:self.mapView
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    completion:nil];

But after it's done the "from-view" is nil, and after one more toggle, both views are nil. 但是,完成后,“从视图”为零,再进行一次切换后,两个视图均为零。 Is there another way to flip between views and keeping both around? 还有另一种方法可以在视图之间切换并保持两者不变吗? Then i don't have to populate and init them again when showing. 然后,我不必在显示时填充并再次初始化它们。 Kind of bad to do that to a map with alot of pins every time the user flips. 每次用户翻转时,对具有大量图钉的地图执行此操作都是很不好的。

From the documentation : 文档中

fromView fromView

The starting view for the transition. 过渡的起始视图。 By default, this view is removed from its superview as part of the transition. 默认情况下,此视图作为过渡的一部分从其超级视图中删除。

toView 查看

The ending view for the transition. 过渡的结束视图。 By default, this view is added to the superview of fromView as part of the transition. 默认情况下,此视图作为过渡的一部分添加到fromView的超级视图中。

Discussion 讨论区

This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. 此方法提供了一种从fromView参数中的视图过渡到toView参数中的视图的简单方法。 By default, the view in fromView is replaced in the view hierarchy by the view in toView. 默认情况下,fromView中的视图在视图层次结构中被toView中的视图替换。 If both views are already part of your view hierarchy, you can include the UIViewAnimationOptionShowHideTransitionViews option in the options parameter to simply hide or show them . 如果两个视图都已经属于视图层次结构,则可以在options参数中包含UIViewAnimationOptionShowHideTransitionViews选项,以简单地隐藏或显示它们

So if you don't have both views already as part of your view hierarchy, why not add them beforehand? 因此,如果您尚未将两个视图都作为视图层次结构的一部分,为什么不事先添加它们呢? You could insert mapview as a subview below tableView (so it doesn't get shown at first) and then call the transition using UIViewAnimationOptionShowHideTransitionViews along UIViewAnimationOptionTransitionFlipFromLeft as options. 您可以将mapview作为子视图插入tableView下面(因此一开始不会显示),然后使用UIViewAnimationOptionShowHideTransitionViewsUIViewAnimationOptionTransitionFlipFromLeft作为选项来调用过渡。

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

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