XcodeLearningViewThe conversion example is described in this article.XcodeMediumViewTutorial on conversion example practice. Let's learn moreXcodeFor more information, see this article.
Flip (similar to flip)ViewEffect: Two implementation methods
SlideViewEffect
Focus on their respective implementations:
Example of flipped view Effect
On the official website
- UIViewAnimationTransitionFlipFromLeft and UIViewAnimationTransitionFlipFromRight
To flip the view left or right.
To use conversion in a UIView animation block, two tasks are required:
1. You must add the conversion as a block parameter.
2. View order should be rescheduled within the block.
The effect code is as follows:
- - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
- // Start Animation Block
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:nil context:context];
- [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];
- //* [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0];
- // Animations [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- //*
- // Commit Animation Block
- [UIView commitAnimations];
- }
Note that this code is written on the touchesEnded event, which also conforms to the flip logic.
The above Code contains // *, that is, two jobs are required.
The first part indicates turning to the left. The flipped object is the upper-level view of the current view and is cached.
The second part indicates the exchange between 0 and 1 in the subview Gallery.
UIView class
Class Method: animation part)
- setAnimationTransition:forView:cache:
- + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache
-
- Sets a transition to apply to a view during an animation block.
Method:
- exchangeSubviewAtIndex:withSubviewAtIndex:
- - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2
-
- Exchanges the subviews at the specified indices.
- index1: The index of the first subview in the receiver.
- index2: The index of the second subview in the receiver.
You can use other methods to implement the exchangeSubviewAtIndex: withSubviewAtIndex: method. For example:
- UIViewController Controller
- UIView v1
- UIView v2
- Controller.view = v1;//v1 front
- Controller.view = v2;//v2 front
Of course, this is only used in practice, but not necessarily. Not implemented with UIViewControllerAnimationResults: At least now I don't know whether UIViewController can be implemented.AnimationEffect.
Another method for implementationAnimationEffect Core Animation Transition: Act on the layer ratherViewSee the following code:
- - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{
- CATransition *animation = [CATransition animation];
- [animation setDelegate:self];
- [animation setDuration:1.0f];
- [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
- [animation setType: kCATransitionPush];
- [animation setSubtype: kCATransitionFromLeft];
- [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
- [[[self superview] layer] addAnimation:animation forKey:@"transitionViewAnimation"];
- }