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