UIView animation does not work

I have the following code for animating a UIView:

[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:self]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mapView.view cache:NO]; [self addSubview:detailView]; [mapView removeFromSuperview]; [UIView commitAnimations]; 

This works when I do not add detailView. In fact, this is equivalent to this:

 [self addSubview:detailView]; [mapView removeFromSuperview]; 
+4
source share
4 answers

I think you have the wrong order. You need to delete the old preview first before adding a new one.

see link for setAnimationTransition: forView: cache:

You can also use CATransition at the view level. and then use layer animations.

if you specifically want to flip the new view, you can also use the presentalModalViewController method for uiviewcontroller.

+1
source

I constantly read your code in textbooks and never worked for me. I always use this:

 UIViewController *mainViewController = [[YourMainViewController alloc] init]; UIViewController *viewControllerToSwitchTo = [[ViewControllerToSwitchTo alloc] init]; [mainViewController presentModalViewController:viewControllerToSwitchTo animated: YES]; 

You can set the lookup style with:

 [setModalTransitionStyle:WhateverModalTransitionStyleYouWant]; 

but make sure this happens before the transition method.

+1
source

This code will not work. From the Apple documentation:

If you want to change the look of the view during the transition - for example, flip from one view to another - then use the container view, an instance of UIView, as follows:

  • Start the animation block.
  • Set the transition as a container.
  • Delete the view in the container view.
  • Add a new view to the container view.
  • Lock animation block.

Thus, the transition should not be applied to your mapView, but to your addition / removal in the reverse order.

+1
source

I had to set the graphics context to UIGraphicsGetCurrentContext()

0
source

Source: https://habr.com/ru/post/1305284/


All Articles