1 //UIView Animation Analysis2 3 #import "ViewController.h"4 5 @interfaceViewcontroller ()6 7@property (nonatomic,strong) UIView *MyView;8 9 @endTen One @implementationViewcontroller A - - the //lazy Loading is a Get method ah --(UIView *) myview{ - if(_myview = =Nil) { -_myview =[[UIView alloc]init]; +_myview.backgroundcolor =[Uicolor Orangecolor]; -_myview.frame = CGRectMake ( -, -, -, -); + } A return_myview; at } - - - --(void) Viewdidload { - [Super Viewdidload]; inSelf.myView.center = Cgpointmake (self.view.center.x,0); - [Self.view Addsubview:_myview]; to } + --(void) Touchesbegan: (nonnull nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event{ the *NSLog (@"begin"); $[UIView animatewithduration:2.0Delay0.0Usingspringwithdamping:0.5Initialspringvelocity:10.0Options0animations:^{Panax NotoginsengNSLog (@"Start Animation"); -Self.myView.center =Self.view.center; the} completion:^(BOOL finished) { +NSLog (@"Complete the animation"); A }]; theNSLog (@" Over"); + - } $ @end
Conclusion:
Block is a C-language pre-prepared code that executes when needed. The animation that the UIView system encapsulates is immediately executed. So after writing the code in the callback, it executes immediately. Start with begin, then start the animation, then asynchronously over, then complete the animation.
UIView Animation Analysis