Animation-IOS development

Source: Internet
Author: User

In IOS, there are two types of animations on the right: 1. UIView view animation 2. Layer animation UIView animation is also Layer-based animation
The animation code format is fixed.

1. UIView Animation

General Mode
[UIView beginAnimations: @ "ddd" context: nil]; // sets an animation.
[UIView commitAnimations]; // submit an animation
These two are required, and then add the animation code in the middle of the two sentences.

[UIView beginAnimations: @ "ddd" context: nil]; // set the animation ddd as the animation name
[UIView setAnimationDuration: 3]; // defines the animation duration
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // setAnimationCurve defines the animation acceleration or deceleration Mode
[UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView: self. window cache: YES];
// Set the animation style forView to which view to implement the animation effect
[UIView setAnimationDelay: 3]; // sets the animation delay duration.
[UIView setAnimationDelegate: self]; // sets the method before and after the animation is executed by setting the animation proxy before commitAnimation.
[UIView setAnimationDidStopSelector: @ selector (stop)]; // sets the method to be executed after the animation ends.
[UIView setAnimationWillStartSelector: @ selector (star)]; // you can specify a method to start executing an animation.
[UIView commitAnimations]; // submit an animation
Typedef enum {
UIViewAnimationTransitionNone, // normal status
UIViewAnimationTransitionFlipFromLeft, // flip from left to right
UIViewAnimationTransitionFlipFromRight, // flip from right to left
UIViewAnimationTransitionCurlUp, // flip up
UIViewAnimationTransitionCurlDown, // flip down
} UIViewAnimationTransition;
Typedef enum {
UIViewAnimationCurveEaseInOut,
UIViewAnimationCurveEaseIn,
UIViewAnimationCurveEaseOut,
UIViewAnimationCurveLinear
} UIViewAnimationCurve;

[UIView beginAnimations: @ "ddd" context: nil]; // sets an animation.
View. frame = CGRectMake (200,200,100,100 );
[UIView commitAnimations]; // submit an animation
When the view is moved from the original frame to the new frame, it will gradually become a gradient instead of being completed in the middle. You can also add it to the middle of the previous frame, which only overlaps various effects.

The following can also be added to [UIView beginAnimations: @ "ddd" context: nil]; [UIView commitAnimations ];

View. transform = CGAffineTransformMakeTranslation (10, 10); // you can set the offset to be offset only once.
View. transform = CGAffineTransformTranslate (view. transform, 10, 10); // you can set the offset multiple times.

Self. view. transform = CGAffineTransformMakeRotation (M_PI); // you can set the degree of rotation to be rotated only once.
Self. view. transform = CGAffineTransformRotate (self. view. transform, M_PI); // rotate multiple times

Self. view. transform = CGAffineTransformMakeScale (1.1, 1.1); // you can set the size to only several times that of the original value at a time.
Self. view. transform = CGAffineTransformScale (self. view. transform, 1.1, 1.1); // change multiple times

Self. view. transform = CGAffineTransformIdentity; // run the command again
Self. view. transform = CGAffineTransformInvert (self. view. transform); // you can run the command multiple times in the direction of the opposite image size.

Block Method
[UIView animateWithDuration: 3 animations: ^ (void ){

// It is equivalent
} Completion: ^ (BOOL finished ){
// This is equivalent to the method to be executed after the animation is executed. You can continue nesting blocks.
}];

2. CAAnimation
You need to add libraries and header files.


Caanimation has multiple subclasses

CABasicAnimation

CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath: @ "opacity"];
// @ "" Contains a variety of strings. You can find relevant information by yourself. Make sure to fill in the correct information before the animation will execute opacity to set the transparency bounds. size to set the size.
[Animation setFromValue: [NSNumber numberWithFloat: 1.0]; // sets the transparency from the beginning.
[Animation setToValue: [NSNumber numberWithFloat: 0.3]; // sets the transparency to a few ends.
[Animation setDuration: 0.1]; // sets the animation time.
[Animation setRepeatCount: 100000]; // sets the repetition time.
[Animation setRepeatDuration: 4]; // The number of repetitions is limited.
[Animation setAutoreverses: NO]; // you can specify whether to set it from 1.0 to 0.3 and then from 0.3 to 1.0. If it is set to NO, the value 1.0 to 0.3 is once.
[Animation setRemovedOnCompletion: YES]; // by default, when the animation is removed
[View. layer addAnimation: animation forKey: @ "abc"]; // executes an animation.

CAKeyframeAnimation

CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath: @ "position"]; // sets the view to go through a series of points from the initial position
NSArray * postionAraay = [NSArray Syntax: [NSValue Syntax: CGPointMake (100, 20)], [NSValue Syntax: CGPointMake (40, 80)], [NSValue valueWithCGPoint: CGPointMake (30, 60)], [NSValue valueWithCGPoint: CGPointMake (20, 40)], [NSValue valueWithCGPoint: CGPointMake (0,100)], nil]; // set a point

NSArray * times = [NSArray flood: [NSNumber numberWithFloat: 0.3], [NSNumber numberWithFloat: 0.5], [NSNumber numberWithFloat: 0.6], [NSNumber numberWithFloat: 0.1], [NSNumber flood: 1.0], nil]; // set the time of the Moving Process

[Animation setKeyTimes: times];
[Animation setValues: postionAraay];
[Animation setDuration: 5]; // sets the animation time.
[BigImage. layer addAnimation: animation forKey: @ "dd"]; // executes an animation.

CATransition

CATransition * animation = [CATransition animation];
Animation. duration = 0.5f;
Animation. timingFunction = UIViewAnimationCurveEaseInOut;
Animation. fillMode = kCAFillModeForwards;
/*
KCATransitionFade;
KCATransitionMoveIn;
KCATransitionPush;
KCATransitionReveal;
*/
/*
KCATransitionFromRight;
KCATransitionFromLeft;
KCATransitionFromTop;
KCATransitionFromBottom;
*/
Animation. type = kCATransitionPush;
Animation. subtype = kCATransitionFromBottom;
[View. layer addAnimation: animation forKey: animation];
Type can also be directly used as a string
/*
Cube
SuckEffect
OglFlip flip
RippleEffect
PageCurl Paging
PageUnCurl
CameraIrisHollowOpen
CameraIrisHollowClose
*/

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.