Implementation of UIView Animation in iPhone Development

Source: Internet
Author: User

IPhone DevelopmentAboutUIView AnimationThe implementation effect is the content to be introduced in this article, mainly to learnUIView AnimationFor a series of implementation results, let's take a look at how this article is implemented. It was previously influenced by a seriesUIView AnimationThis is the only way to write:

Set delegate in an animation, and then call another function in the delegate function.

Today, I decided to check for missing iPhone cookbook code and found the code:

C code

 
 
  1. // Hide the bar button and show the view   
  2. self.navigationItem.rightBarButtonItem = nil;   
  3. [self.view viewWithTag:101].alpha = 1.0f;   
  4.  
  5. // Bounce to 115% of the normal size   
  6. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
  7. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
  8. [UIView setAnimationDuration:0.4f];   
  9. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.15f, 1.15f);   
  10. [UIView commitModalAnimations];   
  11.  
  12. // Return back to 100%   
  13. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
  14. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
  15. [UIView setAnimationDuration:0.3f];   
  16. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.0f, 1.0f);   
  17. [UIView commitModalAnimations];   
  18.  
  19. // Pause for a second and appreciate the presentation   
  20. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];   
  21.  
  22. // Slowly zoom back down and hide the view   
  23. [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];   
  24. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];   
  25. [UIView setAnimationDuration:1.0f];   
  26. [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(0.01f, 0.01f);   
  27. [UIView commitModalAnimations];   
  28.  
  29. // Restore the bar button   
  30. [self.view viewWithTag:101].alpha = 0.0f;  

Tnnd can be written in this way.

Learn new things at the same time.

C code

 
 
  1. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];  

PS. In the past, this example was called Modal View Animation. The iPhone had no idea about this for so long.

Sorry, I got it wrong. It turned out to be the method implemented by the author.

C code

 
 
  1. commitModalAnimations  

The specific code implementation is like this.

Java code

 
 
  1. @interface UIViewDelegate : NSObject   
  2. {   
  3. CFRunLoopRef currentLoop;   
  4. }   
  5. @end   
  6.  
  7. @implementation UIViewDelegate   
  8. -(id) initWithRunLoop: (CFRunLoopRef)runLoop   
  9. {   
  10. if (self = [super init]) currentLoop = runLoop;   
  11. return self;   
  12. }   
  13.  
  14. -(void) animationFinished: (id) sender   
  15. {   
  16. CFRunLoopStop(currentLoop);   
  17. }   
  18. @end   
  19.  
  20. @implementation UIView (ModalAnimationHelper)   
  21. + (void) commitModalAnimations   
  22. {   
  23. CFRunLoopRef currentLoop = CFRunLoopGetCurrent();   
  24.  
  25. UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];   
  26. [UIView setAnimationDelegate:uivdelegate];   
  27. [UIView setAnimationDidStopSelector:@selector(animationFinished:)];   
  28. [UIView commitAnimations];   
  29. CFRunLoopRun();   
  30. [uivdelegate release];   
  31. }   
  32. @end 

Summary:IPhone DevelopmentAboutUIView AnimationThe content of the implementation effect is introduced. I 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.