Use parameter configuration to execute the basic Animation in ios UIView, iosuiview
In ios development, basic animations are generally used in the following types. All animation parameter configurations are roughly the same, but sometimes such configurations are rarely used during development. Generally, it is easier to use code blocks, the Code is also relatively simple. The following is a configuration of common basic animation types.
# Pragma mark -- Action methods-(void) transitionAnimation // transition animation {// set the animation name so that the agent can determine which animation is used. [UIView beginAnimations: @ "TransitionAnimation" context: NULL]; // set the animation duration [UIView setAnimationDuration: 3.0]; // set the animation variation rules-with the following enumerated values in 4 // UIViewAnimationCurveEaseInOut, start and end deceleration // slow at beginning and end // slow, // slow at beginning // slow, // slow at end // UIViewAnimationCurveLinear constant speed [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // set the following enumeration direction for the View transition animation // typedef NS_ENUM (NSInteger, UIViewAnimationTransition) {// UIViewAnimationTransitionNone, // audience, // audience, // UIViewAnimationTransitionCurlUp, // UIViewAnimationTransitionCurlDown, //}; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: _ view cache: NO]; // set the initial state of the View and configure others (here, the View is changed to the previous parameter, and you can remove this Code if you do not need it) [_ view setTransform: CGAffineTransformIdentity]; [_ view setBackgroundColor: [UIColor blackColor]; [_ view setAlpha: 1]; [_ view setCenter: CGPointMake (50, 50)]; // sets the proxy [UIView setAnimationDelegate: self]; // execute the proxy method after the animation ends (when the proxy method is used here, other animation methods can be used to form an animation Group) [UIView setAnimationDidStopSelector: @ selector (animationDidStop: finished: context :)]; // animation end [UIView commitAnimations];}-(void) changeAlphaAnimation // change transparency animation {[UIView beginAnimations: @ "ChangeAlphaAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: Unknown]; [_ view setAlpha: 0.2]; [UIView setAnimationDelegate: self]; [UIView attributes: @ selector (animationDidStop: finished: context :)]; [UIView commitAnimations];}-(void) changeColorAnimation // color change animation {[UIView beginAnimations: @ "ChangeColorAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: finished]; [_ view setBackgroundColor: [UIColor redColor]; [UIView setAnimationDelegate: self]; [UIView progress: @ selector (animationDidStop: finished: context :)]; [UIView commitAnimations];}-(void) rotationAnimation // rotation animation {[UIView beginAnimations: @ "RotationAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; [_ view setTransform: CGAffineTransformRotate (_ view. transform, M_PI_4)]; [UIView setAnimationDelegate: self]; [UIView setAnimationDidStopSelector: @ selector (changeColorAnimation)]; [UIView commitAnimations];}-(void) scareAnimation // zoom in and out the animation {[UIView beginAnimations: @ "ScareAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: animation]; [UIView details: self]; [_ view setTransform: CGAffineTransformScale (_ view. transform, 2, 2)]; [UIView progress: @ selector (rotationAnimation)]; [UIView commitAnimations];}-(void) positionAnimation // displacement animation {[UIView beginAnimations: @ "PositionAnition" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; [UIView setAnimationDelegate: self]; _ view. center = CGPointMake (CGRectGetMidX (self. view. bounds), CGRectGetMidY (self. view. bounds); [UIView setAnimationDidStopSelector: @ selector (scareAnimation)]; [UIView commitAnimations];} // proxy method, there are two other methods to detect the animation and perform other operations-(void) animationDidStop :( NSString *) animationId finished :( NSNumber *) finished context :( void *) context {// determine which animation is and then perform the corresponding operation if ([animationId isEqualToString: @ "ChangeColorAnimation"]) {[self changeAlphaAnimation];} if ([animationId isEqualToString: @ "ChangeAlphaAnimation"]) {[self transitionAnimation];}
Next let's take a look at the usage of the code block. It is very convenient to use the code block and can be called back. In the APP click the menu to dynamically switch between two views or other animations.
<Pre name = "code" class = "objc"> [UIView animateWithDuration: 0.5 animations: ^ {[UIView setAnimationDelay: 0.8]; // configure the animation latency _ currentView. center = CGPointMake (X, Y); // you can configure newView for multiple views. center = CGPointMake (X, Y);} completion: ^ (BOOL finished) {// code block after execution}];