IOS Core Animation Detailed (v) catransition

Source: Internet
Author: User

Welcome to my iOS SDK detailed column
Http://blog.csdn.net/column/details/huangwenchen-ios-sdk.html
Unknowingly iOS animated series of articles have been written to the fifth, here, can easily find my previous writing about the four articles about animation.

Preface: CATransition is a subclass of Caanimation, the most important use is to define the transition animation of view reload. With this well-integrated class, you can create good results with just a few lines of code.

Effect One

Motion diagram

Core Code,

    CATransition * transition = [CATransition animation];    transition.type = kCATransitionFade;    transition.duration1.0;    [self.imageview.layer addAnimation:transition forKey:@"ToNext"];    self.imageview.image = nextImage;

The complete code
Drag a imageview on top of the storyboard and drag outlet

 @interface viewcontroller ()@property(Weak,nonatomic)Iboutlet Uiimageview*imageview;@property(Assign,nonatomic)NsintegerCurrentindex;@end @implementation viewcontroller -(Nsarray*) imagesnamesarray{return@[@"Meidui1.jpg",             @"Meidui2.jpg"];} - (void) Viewdidload {[SuperViewdidload]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] Initwithtarget: SelfAction@selector(Changetonextimage)]; Self. ImageView. userinteractionenabled=true; [ Self. ImageViewADDGESTURERECOGNIZER:TAP]; Self. Currentindex=0;} -(void) changetonextimage{ Self. Currentindex= ( Self. Currentindex+1) %2;NSString* ImageName = [[ SelfImagesnamesarray] Objectatindex: Self. Currentindex];UIImage* NextImage = [UIImageImagenamed:imagename];    catransition * transition = [catransition animation]; Transition. Type= Kcatransitionfade; Transition. Duration=1.0; [ Self. ImageView. LayerAddanimation:transition forkey:@"Tonext"]; Self. ImageView. Image= NextImage;}
Effect Two

Motion diagram

Code

catransition * transition = [Catransition animation];Transition. Duration=1.0;//Animation intervalTransition. Type= Kcatransitionmovein;//main type, determines animation effectTransition. Startprogress=0.0;//StartTransition. Endprogress=1.0;//EndTransition. Subtype= Kcatransitionfromright;//Minor kind, determines the direction of animationTransition. Timingfunction= [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout];//Time function[Self. ImageView. LayerAddanimation:transition forkey:@"Tonext"];Self. ImageView. Image= NextImage;

There are four types of main species

NSStringconst//消退NSStringconst kCATransitionMoveIn;//移入NSStringconst kCATransitionPush;//pushNSStringconst kCATransitionReveal;//退出

There are also four types of secondary species

NSStringconst kCATransitionFromRight;NSStringconst kCATransitionFromLeft;NSStringconst kCATransitionFromTop;NSStringconst kCATransitionFromBottom;

Copyright NOTICE: This article is for bloggers original article, if you need to reprint please indicate the source

IOS Core Animation Detailed (v) catransition

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.