UIView animation not working
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:
- Begin an animation block.
- Set the transition on the container view.
- Remove the subview from the container view.
- Add the new subview to the container view.
- 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()
精彩评论