There are five types of animations in iOS: Uiview<block>,caanimation<cabasicanimation,catransition,cakeyframeanimation> Nstimer
One: UIView animation General Way
- [uiview beginanimations:@ "ddd" context:nil];//set animation
- [uiview commitanimations];//Commit animation
- These two are required, and then add the animated code in the middle of the two sentences
- [UIView beginanimations:@ "DDD" context:nil];//set animated DDD to animated name
- [ uiview setanimationduration:3];//Define animation duration
- [Uiview setanimationcurve: Uiviewanimationcurveeaseinout]; Setanimationcurve to define the animation acceleration or deceleration mode
- [Uiview setanimationtransition:uiviewanimationtransitioncurldown ForView:self.window Cache:yes];
- //Animate the style forview for which view implements this animation effect
- [uiview setanimationdelay:3];//Set animation delay for how long to execute
- [uiview setanimationdelegate:self];//animate the agent implementation before and after the animation method before commitanimation settings
- [Uiview setanimationdidstopselector: @selector (stop)];//sets the method to be executed after the animation ends
- [Uiview setanimationwillstartselector: @selector (Star)];//set the way the animation will begin executing
- [UIView commitanimations];//Submit Animation
-
- typedef enum {
- Uiviewanimationtransitionnone,//Normal status
- Uiviewanimationtransitionflipfromleft,//flip from left to right
- Uiviewanimationtransitionflipfromright,//flip from right to left
- Uiviewanimationtransitioncurlup,//PAGE UP
- Uiviewanimationtransitioncurldown,//Page Down
- } uiviewanimationtransition;
- typedef enum {
- Uiviewanimationcurveeaseinout,
- Uiviewanimationcurveeasein,
- Uiviewanimationcurveeaseout,
- Uiviewanimationcurvelinear
- } Uiviewanimationcurve;
- [UIView beginanimations:@ "ddd" context:nil]; Set animation
- View.frame = CGRectMake (200, 200, 100, 100);
- [UIView commitanimations]; Submit Animation
- When the view moves from the original frame to the new frame, it slowly fades instead of just finishing the middle and adding it to the middle of the paragraph.
- The following can also be added to [UIView beginanimations:@ "ddd" context:nil]; [UIView commitanimations];
- View.transform = Cgaffinetransformmaketranslation (10, 10);//Set offset only once with respect to the original
- View.transform = Cgaffinetransformtranslate (View.transform, 10, 10); Set offset offset multiple times
- Self.view.transform = Cgaffinetransformmakerotation (M_PI);//Set rotation can only be rotated once
- Self.view.transform = Cgaffinetransformrotate (Self.view.transform, M_PI); Rotate multiple times
- Self.view.transform = Cgaffinetransformmakescale (1.1, 1.1); Setting the size can only change once the value is several times the original
- Self.view.transform = Cgaffinetransformscale (Self.view.transform, 1.1, 1.1);//Change multiple times
- Self.view.transform = cgaffinetransformidentity;//back to the original to execute once
- Self.view.transform = Cgaffinetransforminvert (self.view.transform);//get opposite look size direction position executed multiple times
Here I implemented a custom animation method, easy to use, only need to call to achieve a good function.
Implementation of the method
-(void) Uiviewanimation: (uiview*) View frame: (CGRect) frame type: (int) type alpha: (float) Alpha Duration: (float) Duration
{
The corresponding parameter is implemented in the method, the call only need to input the parameters required in the method can be very good call this method, and realize the desired function!
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:duration];
[UIView Setanimationcurve:type];
[UIView setanimationdelegate:self];
View.alpha=alpha;
View.frame=frame;
[UIView commitanimations];
}
Calling methods
[Self Uiviewanimation:downview frame:cgrectmake (0, height, +,] type:uiviewanimationcurveeaseout alpha:1 duration : 0.3];
Block mode
- [UIView Animatewithduration:3 animations:^ (void) {
- This is the equivalent of between Begin and Commint.
- }completion:^ (BOOL finished) {
- This is equivalent to the way the animation executes after execution, and you can continue nesting the block
- }];
Advanced Block Animation (Next) inline
-(void) changeuiview{[UIView animatewithduration:2 delay:0 options:uiviewanimationoptioncurveeaseout animations:^ (void) {moveview.alpha = 0.0; }completion:^ (BOOL finished) {[UIView animatewithduration:1 delay:1.0 Options:uiviewanimationoptionautore Verse | Uiviewanimationoptionrepeat animations:^ (void) {[UIView setanimationrepeatcount:2.5]; Moveview.alpha = 1.0; }completion:^ (BOOL finished) {}]; }]; }
Two:. Caanimation
Need to add libraries, and include header files
How many sub-categories are caanimation
Cabasicanimation
- Cabasicanimation *animation = [cabasicanimation animationwithkeypath:@ "opacity"];
- @ "" In a variety of strings, you can find relevant information, be sure to fill in the right, the animation will do opacity set transparency bounds.size set size
- [Animation Setfromvalue:[nsnumber numberwithfloat:1.0]; Set transparency from several beginnings
- [Animation Settovalue:[nsnumber numberwithfloat:0.3]];//set Transparency to a few ends
- [Animation setduration:0.1]; Set animation time
- [Animation setrepeatcount:100000];//Set Repetition time
- [Animation Setrepeatduration:4]; Will limit the number of repetitions
- [Animation setautoreverses:no];//set whether from 1.0 to 0.3 again from 0.3 to 1.0 for one time if set to NO then 1.0 to 0.3 for one time
- [Animation Setremovedoncompletion:yes]; Move out animation when finished the default is also
- [View.layer addanimation:animation forkey:@ "abc"];//performing animations
Cakeyframeanimation
- Cakeyframeanimation *animation = [cakeyframeanimation animationwithkeypath:@ "position"];//set view from initial position through a series of points
- Nsarray *postionaraay = [Nsarray arraywithobjects:[nsvaluevaluewithcgpoint:cgpointmake (+)], [NSValue Valuewithcgpoint:cgpointmake (],[nsvalue)
- Valuewithcgpoint:cgpointmake (],[nsvalue valuewithcgpoint:cgpointmake)],[nsvalue valueWithCGPoint: Cgpointmake (0, +)],nil];//set point
- Nsarray *times = [Nsarray arraywithobjects:[nsnumber numberwithfloat:0.3],[nsnumber NumberWithFloat:0.5],[NSNumber Numberwithfloat:0.6],[nsnumber Numberwithfloat:0.1],[nsnumber
- Numberwithfloat:1.0], nil]; Set the time for the move process
- [Animation Setkeytimes:times];
- [Animation Setvalues:postionaraay];
- [Animation Setduration:5]; Set animation time
- [Bigimage.layer addanimation:animation forkey:@ "DD"]; Performing animations
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 used directly with the string
- /*
- Cube
- Suckeffect Roll Away
- Oglflip Flip
- Rippleeffect Water Waves
- Pagecurl page
- Pageuncurl
- Camerairishollowopen
- Camerairishollowclose
- */
Three: Nstimer
This is a timer to manipulate the animation method, he can combine the above method to achieve the diversification of animation!
- -(void) OnTimer {
- Imageview.center = Cgpointmake (imageview.center.x + delta.x,
- Imageview.center.y + delta.y);
- if (imageview.center.x > Self.view.bounds.size.width-ballradius | |
- Imageview.center.x < Ballradius)
- delta.x =-delta.x;
- if (Imageview.center.y > Self.view.bounds.size.height-ballradius | |
- Imageview.center.y < Ballradius)
- DELTA.Y =-DELTA.Y;
- }
- -(void) Viewdidload {
- Ballradius = IMAGEVIEW.BOUNDS.SIZE.WIDTH/2;
- [Slider Setshowvalue:yes];
- Delta = cgpointmake (12.0,4.0);
- Timer = [Nstimer scheduledTimerWithTimeInterval:slider.value
- Target:self
- Selector: @selector (OnTimer)
- Userinfo:nil
- Repeats:yes];
- [Super Viewdidload];
- }
- -(Ibaction) slidermoved: (ID) Sender {
- [Timer invalidate];
- Timer = [Nstimer scheduledTimerWithTimeInterval:slider.value
- Target:self
- Selector: @selector (OnTimer)
- Userinfo:nil
- Repeats:yes];
- //
- Timer = [Nstimer scheduledtimerwithtimeinterval:?
- Invocation:?
- Repeats:yes];
- }
iOS Animation programming