Вопрос

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. 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

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.

Discussion

This method provides a simple way to transition from the view in the fromView parameter to the view in the toView parameter. By default, the view in fromView is replaced in the view hierarchy by the view in 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.

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top