UIView animation examples and practices for Xcode Learning

Source: Internet
Author: User

XcodeLearningUIView AnimationExamples and practices are the content to be introduced in this article.UIView AnimationExamples and practicesXcodeTo learn and understandXcodeFirst, let's take a look at the details.

Here is an example of the fade-in and fade-out effect. The object relationship diagram is as follows:

 
 
  1. SampleAppDelegate  
  2.     HelloController init  
  3.         ToggleView init  
  4.             UIImageView init  
  5.             self addSubview  
  6.             UIImageView release  
  7.         ToggleView release 

Release other objects

When a fade-in or fade-out event is triggered in the touchesBegan event of ToggleView, the animation of ToggleView itself is implemented to control the fade-out effect of UIImageView on the Child view, the UIImageView as a subview does not allow the exchange of touch imgView. userInteractionEnabled = NO;), only controls the display status.

Now I want to learn the new method of UIView. The following shows how to implement the fade-in and fade-out effect;

 
 
  1. // Perform the fade out or fade in
  2. CGContextRef context = UIGraphicsGetCurrentContext ();
  3. [UIView beginAnimations: nil context: context];
  4. [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
  5. [UIView setAnimationDuration: 1.0];
  6. [[Self viewWithTag: IMAGE_VIEW_TAG] setAlpha :( float) isVisible]; // Note: This sets the display attribute for the current subview.
  7. [UIView commitAnimations];

UIView class

Class Method: animation part)

 
 
  1. beginAnimations:context:  
  2.  
  3. + (void)beginAnimations:(NSString *)animationID context:(void *)context  
  4.  
  5. Marks the beginning of a begin/commit animation block.  
  6.  
  7. setAnimationCurve:  
  8.  
  9. + (void)setAnimationCurve:(UIViewAnimationCurve)curve  
  10.  
  11. Sets the curve to use when animating property changes within an animation block.  
  12.  
  13. setAnimationDuration:  
  14.  
  15. + (void)setAnimationDuration:(NSTimeInterval)duration  
  16.  
  17. Sets the duration (measured in seconds) of the animations in an animation block.  
  18.  
  19. commitAnimations  
  20.  
  21. + (void)commitAnimations  
  22.  
  23. Marks the end of a begin/commit animation block and schedules the animations for execution. 

Constants/Constant

 
 
  1. UIViewAnimationCurveEaseInOut  
  2.  
  3. An option for specifying an ease-in ease-out timing curve for the animation. An ease-in ease-out curve causes the animation to begin slowly,
  4.  accelerate through the middle of its duration, and then slow again before completing. This is the default curve for most animations.  
  5.  
  6. UIViewAnimationCurveEaseIn  
  7.  
  8. An option for specifying an ease-in timing curve for the animation. An ease-in curve causes the animation to begin slowly, 
  9. and then speed up as it progresses.  
  10.  
  11. UIViewAnimationCurveEaseOut  
  12.  
  13. An option for specifying an ease-out timing curve for the animation. An ease-out curve causes the animation to begin quickly, 
  14. and then slow down as it finishes.  
  15.  
  16. UIViewAnimationCurveLinear  
  17.  
  18. An option for specifying a linear timing curve for the animation. A linear animation curve causes an animation to occur evenly over its duration. 

Summary:XcodeLearningUIView AnimationI hope this article will help you!

Related Article

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.