IPhone DevelopmentContinuous CreationAnimationThe case is the content to be introduced in this article.Iphone DevelopmentMedium continuityAnimation. Let's take a look at the details. InIphone Development, We sometimes need to create continuousAnimationResults To improve user experience.
ContinuousAnimationJust a paragraphAnimationWhen calling another animation, make sure that the two animations do not overlap. In this article, we do not plan to use CAKeyframeAnimation to create continuous animation blocks, although CAKeyframeAnimation is easier to implement in other blog posts)
There are two possible methods:
1. Increase the latency so that the second animation can be started after the first animation ends [effecmselector: withObject: afterDelay:])
2. Specify the animation delegate callback animationDidStop: finished: context :)
It is easier from the programming point of view. Next we will introduce a new method-commitModalAnimations-to extend the class UIView method. call this method instead of calling the commitAnimations method. It creates a new runloop, which stops only when the animation ends.
This ensures that the commitModalAnimations method returns control to the calling method only after the animation ends. This extension method can be used to put the animation block into the Code in order, you do not need to make any other modifications to avoid overlapping animations.
The Code is as follows:
- @interface UIView (ModalAnimationHelper)
- + (void) commitModalAnimations;
- @end
- @interface UIViewDelegate : NSObject
- {
- CFRunLoopRef currentLoop;
- }
- @end
- @implementation UIViewDelegate
- -(id) initWithRunLoop: (CFRunLoopRef)runLoop
- {
- if (self = [super init]) currentLoop = runLoop;
- return self;
- }
- (void) animationFinished: (id) sender
- {
- CFRunLoopStop(currentLoop);
- }
- @end
- @implementation UIView (ModalAnimationHelper)
- + (void) commitModalAnimations
- {
- CFRunLoopRef currentLoop = CFRunLoopGetCurrent();
- UIViewDelegate *uivdelegate = [[UIViewDelegate alloc] initWithRunLoop:currentLoop];
- [UIView setAnimationDelegate:uivdelegate];
- [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
- [UIView commitAnimations];
- CFRunLoopRun();
- [uivdelegate release];
- }
- @end
Usage:
- [self.view viewWithTag:101].alpha = 1.0f;
- // Bounce to 115% of the normal size
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.4f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.15f, 1.15f);
- [UIView commitModalAnimations];
- // Return back to 100%
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.3f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(1.0f, 1.0f);
- [UIView commitModalAnimations];
- // Pause for a second and appreciate the presentation
- [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];
- // Slowly zoom back down and hide the view
- [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:1.0f];
- [self.view viewWithTag:101].transform = CGAffineTransformMakeScale(0.01f, 0.01f);
- [UIView commitModalAnimations];
Summary:IPhone onContinuous CreationAnimationI hope this article will help you with the introduction of the case!