Xcode learning-view conversion example (1)

Source: Internet
Author: User

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

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

 
 
  1. - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{      
  2. // Start Animation Block     
  3.  CGContextRef context = UIGraphicsGetCurrentContext();      
  4.  [UIView beginAnimations:nil context:context];      
  5.  [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];  
  6.  //*    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];      
  7.  [UIView setAnimationDuration:1.0];         
  8.  // Animations    [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];  
  9.  //*         
  10.  // Commit Animation Block      
  11.  [UIView commitAnimations];  
  12.  } 

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)

 
 
  1. setAnimationTransition:forView:cache:  
  2. + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache  
  3.  
  4. Sets a transition to apply to a view during an animation block. 

Method:

 
 
  1. exchangeSubviewAtIndex:withSubviewAtIndex:  
  2.     - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2  
  3.  
  4.     Exchanges the subviews at the specified indices.  
  5.     index1: The index of the first subview in the receiver.  
  6.     index2: The index of the second subview in the receiver. 

You can use other methods to implement the exchangeSubviewAtIndex: withSubviewAtIndex: method. For example:

 
 
  1. UIViewController Controller  
  2.     UIView v1  
  3.     UIView v2  
  4. Controller.view = v1;//v1 front  
  5. 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:

 
 
  1. - (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event{      
  2. CATransition *animation = [CATransition animation];      
  3. [animation setDelegate:self];      
  4. [animation setDuration:1.0f];      
  5. [animation setTimingFunction:UIViewAnimationCurveEaseInOut];     
  6. [animation setType: kCATransitionPush];      
  7. [animation setSubtype: kCATransitionFromLeft];         
  8. [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];      
  9. [[[self superview] layer] addAnimation:animation forKey:@"transitionViewAnimation"];    
  10.  } 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.