Xcode's worthless animated Uiimageview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.