Understanding the Animatewithduration method making an animation becomes worthless
The code creates a uiimageview and then joins the Self.view container
Call the Click Screen Touchesbegan method to perform the animation
#import "ViewController.h"@interfaceViewcontroller () @property (nonatomic,weak) Uiimageview*Imgview;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; CGFloat CGW=Self.view.bounds.size.width; CGFloat IMGW=174; CGFloat IMGH=272; CGFloat CgY= (CGW-IMGW) *0.5; Uiimageview* imgtype=[[Uiimageview alloc]init]; Imgtype.frame=CGRectMake (CgY, CgY, IMGW, IMGH); Imgtype.image=[uiimage imagenamed:@"timg"]; Imgtype.contentmode=Uiviewcontentmodescaleaspectfill; Self.imgview=Imgtype; Self.imgview.alpha=1;//Set Transparency[Self.view AddSubview:self.imgview]; }-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{ //Animation 1//[self animationPlay1]; //Animation 2//[self animationPlay2]; //Animation 3//[self animationPlay3]; //Animation 4[self animationPlay4];}/** animations always slide and disappear*/-(void) animationplay1{/** Animatewithduration: The time to perform the animation animations: code executed*/[UIView animatewithduration:2.0animations:^{CGRect temp=Self.imgview.frame; TEMP.ORIGIN.Y+= $; Self.imgview.alpha=0.1;//Set TransparencySelf.imgview.frame=temp; }];}/** Swipe down and go back*/-(void) animationplay2{/** Animatewithduration: Time to perform animation animations: Code completion executed: callback function to execute code*/[UIView animatewithduration:1.5animations:^{CGRect temp=Self.imgview.frame; TEMP.ORIGIN.Y+= -; Self.imgview.frame=temp;} Completion:^(BOOL finished) {CGRect temp=Self.imgview.frame; TEMP.ORIGIN.Y-= -; Self.imgview.frame=temp;}];}/** Swipe down and go back for 1 seconds*/-(void) animationplay3{/** Animatewithduration: Animation time delay: Delay time options:kniloptions This is generally set to kniloptions that is 0 animations: The animation code to be executed Completion: callback function*/[UIView animatewithduration:1.5Delay1.0Options:kniloptions animations:^{CGRect temp=Self.imgview.frame; TEMP.ORIGIN.Y+= -; Self.imgview.frame=temp;} Completion:^(BOOL finished) {CGRect temp=Self.imgview.frame; TEMP.ORIGIN.Y-= -; Self.imgview.frame=temp;}];}/** Enlarge image and zoom back*/-(void) animationplay4{cgfloat CGW=Self.view.bounds.size.width; //cgfloat cgh=self.view.bounds.size.height;cgfloat IMGW=Self.imgview.bounds.size.width; CGFloat CgY= (CGW-IMGW) *0.5; [UIView animatewithduration:1.5animations:^{CGRect temp=Self.imgview.frame; Temp=cgrectmake (0, CgY, Self.view.bounds.size.width, self.view.frame.size.height-CgY); Self.imgview.frame=temp; Self.imgview.alpha=0.0;//Set Transparency} Completion:^(BOOL finished) {[UIView animatewithduration:2.0animations:^{cgfloat CGW=Self.view.bounds.size.width; CGFloat IMGW=174; CGFloat IMGH=272; CGFloat CgY= (CGW-IMGW) *0.5;//CGRect temp=self.imgview.frame;//Temp=cgrectmake (CgY, CgY, IMGW, IMGH);Self.imgview.alpha=1.0;//Set TransparencySelf.imgview.frame=CGRectMake (CgY, CgY, IMGW, IMGH); }]; }]; }@end
View Code
Xcode's worthless animated Uiimageview