Ios-uiview Animation
Today's theme is UIView's animation.
Animations that are uiview in iOS are encapsulated based on the Calayer animation.
Animation is a static picture through a certain frequency display, giving people the effect of animation.
UIView Animation has the implementation of class-based methods and blocks based on block methods.
I. UIView use of the implementation of class-based methods
class method List:
@interface UIView (uiviewanimation) + (void) Beginanimations: (NSString *) Animationid context: (void *) context; Additional context info passed to would start/did stop selectors. Begin/commit can nested+ (void) commitanimations; Starts up any animations if the top level animation is commited//no getters. If called outside animation block, these setters has no effect.+ (void) Setanimationdelegate: (id) delegate; default = nil+ (void) Setanimationwillstartselector: (SEL) selector; Default = NULL. -animationwillstart: (NSString *) Animationid context: (void *) context+ (void) Setanimationdidstopselector: (SEL) Selector Default = NULL. -animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context: (void *) context+ (void) Setanimationduration: (nstimeinterval) duration; default = 0.2+ (void) Setanimationdelay: (nstimeinterval) delay; Default = 0.0+ (void) Setanimationstartdate: (NSDate *) StartDate; Default = Now ([NSDate Date]) + (void) Setanimationcurve: (Uiviewanimationcurve) curve; default = uiviewanimationcurveeaseinout+ (void) Setanimationrepeatcount: (float) repeatcount; Default = 0.0. May be fractional+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses; Default = NO. Used if repeat count is non-zero+ (void) Setanimationbeginsfromcurrentstate: (BOOL) fromcurrentstate; Default = NO. If YES, the current view position are always used for new animations--allowing animations to ' pile up ' on each other. Otherwise, the last end of the state was used for the animation (the default). + (void) Setanimationtransition: (Uiviewanimationtrans ition) Transition Forview: (UIView *) View cache: (BOOL) cache; Current Limitation-only one per Begin/commit block+ (void) setanimationsenabled: (BOOL) enabled; Ignore any attribute changes while set.+ (BOOL) areanimationsenabled;+ (void) Performwithoutanimation: (void (^) (void)) Actionswithoutanimation Ns_available_ios (7_ 0); @end
1.+ (void) Beginanimations: (NSString *) Animationid context: (void *) context;
This method is the starting point of the animation and it always appears in pairs with commitanimation.
2.+ (void) commitanimations
Commit animations,
The other is mainly used to set the animation of the agent, the execution time, delay the execution of the animation, whether automatic repetition, repetition of the number of times and so on. Here's how they're used.
-(void) classmethodanimation{ [UIView beginanimations:@ "animation" context:nil]; Sets the number of animation repetitions [UIView setanimationrepeatcount:10.]; Start animation change its position from Originpoint (0,0) stale originpoint (100,100) anim.frame = CGRectMake (+, +, +); Set the animation curve, that is, the animation effect [UIView setanimationcurve:uiviewanimationcurveeaseinout]; Set animation delay [UIView setanimationdelay:4]; Set Animation agent [UIView setanimationdelegate:self]; Sets the time when the animation stops [UIView setanimationdidstopselector: @selector (animationstop)]; Set animation execution Time [UIView setanimationduration:10]; Sets whether the animation automatically reverses [UIView Setanimationrepeatautoreverses:yes]; Sets the method that is called when the animation starts [UIView setanimationwillstartselector: @selector (startanimation)]; [UIView commitanimations];}
Console Run output: (mainly the animation agent method call, animation effect See demo)
2015-04-06 08:28:14.230 viewanimation[1299:49180] the animation stopped. -[viewcontroller Startanimation]
2015-04-06 08:28:16.227 viewanimation[1299:49180] the animation stopped. -[viewcontroller Animationstop]
Two. UIView Animation block method
@interface UIView (uiviewanimationwithblocks) + (void) Animatewithduration: (nstimeinterval) duration delay: ( Nstimeinterval) Delay options: (uiviewanimationoptions) options animations: (void (^) (void)) Animations completion: ( void (^) (BOOL finished)) Completion Ns_available_ios (4_0); + (void) Animatewithduration: (nstimeinterval) duration Animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) Completion Ns_available_ios (4_0); Delay = 0.0, options = 0+ (void) Animatewithduration: (nstimeinterval) duration animations: (void (^) (void)) animations NS _available_ios (4_0); Delay = 0.0, options = 0, completion = null+ (void) Animatewithduration: (nstimeinterval) Duration delay: (nstimeinterval) Delay usingspringwithdamping: (cgfloat) dampingratio initialspringvelocity: (cgfloat) Velocity options: ( uiviewanimationoptions) options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished)) completion Ns_available_ios (7_0); + (void) Transitionwithview: (UIView *) View Duration: (nstimeinterval)Duration options: (uiviewanimationoptions) options animations: (void (^) (void)) animations completion: (void (^) (BOOL Finished)) Completion Ns_available_ios (4_0); + (void) Transitionfromview: (UIView *) Fromview Toview: (UIView *) Toview Duration: (nstimeinterval) Duration options: (uiviewanimationoptions) options completion: (void (^) (BOOL finished)) Completion Ns_available_ios (4_0); Toview added to Fromview.superview, Fromview removed from its superview+ (void) Performsystemanimation: ( uisystemanimation) Animation onviews: (Nsarray *) views Options: (uiviewanimationoptions) options animations: (void (^) ( void)) Parallelanimations completion: (void (^) (BOOL finished)) Completion Ns_available_ios (7_0); @end
The block's animated effect is to include what you want to change in block animation blocks.
-(void) blockanimation{ [UIView animatewithduration:5 animations:^{ anim.frame = cgrectmake (100, 100, 50, 50); }]; [UIView animatewithduration:5 animations:^{ anim.frame = CGRectMake (n, A, (); Anim.backgroundcolor = [Uicolor graycolor]; } completion:^ (BOOL finished) { NSLog (@ "Block animation complet operation"); }];}
Operation control state output effect:
2015-04-06 08:33:49.944 viewanimation[1359:51632] block animation complet operation
Summary of two animations:
Animation is implemented by block to include animated content into blocks, and the beginanimation and commitsanimation functions are used to animate the containing animation, which is the execution property of the animation by setting the parameters.
Ios-uiview Animation