Transition animations
First, transition animation simple Introduction
A subclass of Caanimation, used for transition animations, to provide layers with animated effects for moving out of the screen and moving into the screen. iOS has less transition animations than Mac OS X
Uinavigationcontroller is the animation effect of pushing the controller's view into the screen via catransition
Attribute parsing:
Type: Animation transition types
Subtype: Animation transition Direction
Startprogress: Start of Animation (percentage in overall animation)
Endprogress: End of Animation (percentage in overall animation)
Second, the Transition animation code example
1. Interface Construction
2. Implementing the Code
1//2//Yyviewcontroller.m3//13-Transitions Animation4//5//Created by Apple on 14-6-21.6//Copyright (c) 2014 itcase. All rights reserved.7//89#import"YYViewController.h"1011@interfaceYyviewcontroller ()@property (nonatomic,assign)IntIndex@property (Weak, nonatomic) Iboutlet Uiimageview *IconView;14-(Ibaction) Preonclick: (UIButton *) sender;-(Ibaction) Nextonclick: (UIButton *) sender;1718@end1920@implementationYyviewcontroller21st22-(void) Viewdidload23{24[Super Viewdidload];self.index=1;2627}28-(Ibaction) Preonclick: (UIButton *) Sender {self.index--;31if (self.index<1) {self.index=7;33}Self.iconview.image=[uiimage imagenamed: [NSString stringWithFormat:@"%d.jpg", Self.index]];3536//Create a core animationPanax Notoginseng catransition *ca=[Catransition animation];38//Tell me what animations to perform39//Setting over effectsCa.type=@"Cube";41//Set excessive direction of animation (left)Ca.subtype=Kcatransitionfromleft;43//Set the time for the animationca.duration=2.0;45//Add animations46[Self.iconView.layer ADDANIMATION:CA Forkey:nil];47}4849//Next one(ibaction) Nextonclick: (UIButton *) Sender {Wuyi self.index++;52if (self.index>7) {self.index=1;54}Self.iconview.image=[uiimage imagenamed: [NSString stringWithFormat:@"%d.jpg", Self.index]];5657//1. Create a core animationCatransition *ca=[Catransition animation];5960//1.1 Tell what animations to perform61//1.2 Setting over effectsCa.type=@"Cube";63//1.3 Animating the excessive direction (right)Ca.subtype=Kcatransitionfromright;65//1.4 Setting the animation timeca.duration=2.0;67 //1.5 set the starting point of the animation 68 ca.startprogress=0.5;//70 Span style= "color: #008000;" >// ca.endprogress=0.5; 71 72 //2. Add animation 73 [Self.iconView.layer ADDANIMATION:CA Forkey : nil]; 74 }75 @end
Click on the previous one, or the next one, to show the corresponding animation effect.
Single View Transitions
1- (void) Viewdidload2 {3 [Super Viewdidload];4 5 //Instantiate ImageView6Uiimageview *imageview =[[Uiimageview alloc]initwithframe:self.view.bounds];7UIImage *image = [UIImage imagenamed:@"1.jpg"];8 [ImageView setimage:image];9 Ten [Self.view Addsubview:imageview]; One ASelf.imageview =ImageView; - - //3. Initializing Data theNsmutablearray *arraym = [Nsmutablearray arraywithcapacity:9]; - - for(Nsinteger i =1; I <Ten; i++) { -NSString *filename = [NSString stringWithFormat:@"%d.jpg", I]; +UIImage *image =[UIImage imagenamed:filename]; - + [Arraym addobject:image]; A } at -Self.imagelist =Arraym; - } - -- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event - { in[UIView transitionWithView:self.imageView Duration:1.0fOptions:uiviewanimationoptiontransitionflipfromleft animations:^{ - to //what is displayed after the view is reversed in this setting + -Self.imageView.tag = (Self.imageView.tag +1) %Self.imageList.count; the [Self.imageview Setimage:self.imagelist[self.imageview.tag]]; *} completion:^(BOOL finished) { $NSLog (@"Reverse Completion");Panax Notoginseng }]; - the}
Multi-View Transitions
1 /*2 when a double view transitions, the parent view of the go-out view is released3 4 It is highly recommended to use but view transitions, if single view transitions do not meet the requirements, you can usually consider switching the view controller5 */6- (void) Viewdidload7 {8 [Super Viewdidload];9 TenUIView *view2 =[[UIView alloc]initwithframe:self.view.bounds]; One [View2 Setbackgroundcolor:[uicolor bluecolor]; ASelf.subview2 =View2; - -UIView *view1 =[[UIView alloc]initwithframe:self.view.bounds]; the [View1 setbackgroundcolor:[uicolor redcolor]; - [Self.view Addsubview:view1]; -Self.subview1 =View1; - } + -- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event + { A //in two-view transitions, we can determine who gets in and out of a parent view . atUIView *fromview =Nil; -UIView *toview =Nil; - - if(Self.subView1.superview = =Nil) { - //description SubView1 to be transferred to -Toview =Self.subview1; inFromview =Self.subview2; -}Else { to //description SubView2 to be transferred to +Toview =Self.subview2; -Fromview =Self.subview1; the } * $[UIView transitionfromview:fromview Toview:toview Duration:1.0fOptions:uiviewanimationoptiontransitionflipfromtop completion:^(BOOL finished) {Panax Notoginseng -NSLog (@"transition Complete"); the //after each transition, the parent view of the participating Transitions view is adjusted, so the properties that participate in the transition view need to be strongly referenced + //after the transition, the entry view will have two strong references, one is the view controller, the other is the view ANSLog (@"Sub View 1%@", Self.subView1.superview); theNSLog (@"Sub View 2%@", Self.subView2.superview); + }]; -}
iOS development--animation programming OC & (iv) Transition animation