开发者

UIView animation not working

开发者 https://www.devze.com 2022-12-24 15:47 出处:网络
I have the following code to do a UIView animation: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0];

I have the following code to do a UIView animation:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAni开发者_如何学CmationTransition:UIViewAnimationTransitionFlipFromRight forView:mapView.view cache:NO];
[self addSubview:detailView];
[mapView removeFromSuperview];
[UIView commitAnimations];

It works when I dont add the detailView. What actually happens is the equivalent of this:

[self addSubview:detailView];
[mapView removeFromSuperview];


i think you have the order wrong. you need to remove the old subview first before adding the new one.

see reference for setAnimationTransition:forView:cache:

you can also use CATransition on the layer of a view. and then use layer animations.

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


I have seen your code in tutorials all the time and never works 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 view changing style with:

[setModalTransitionStyle:WhateverModalTransitionStyleYouWant];

but make sure this goes before the transition method.


That code won't work. From Apple's documentation:

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

  1. Begin an animation block.
  2. Set the transition on the container view.
  3. Remove the subview from the container view.
  4. Add the new subview to the container view.
  5. Commit the animation block.

So the transition should be applied to self not your mapView, and your add/remove are in reverse order.


I had to set the graphics context to UIGraphicsGetCurrentContext()

0

精彩评论

暂无评论...
验证码 换一张
取 消