iOS animation effects

Source: Internet
Author: User

Reprint: Http://www.cnblogs.com/ludashi/p/4160208.html. Package Animation Method 1. The encapsulation method of animating with Catransition is as follows, see the annotation for each code. 1 #pragma catransition Animation implementation 2-(void) Transitionwithtype: (NSString *) type Withsubtype: (NSString *) subtype Forview: (UIV Iew *) View 3 {4//Create Catransition object 5 catransition *animation = [catransition animation]; 6 7//Set motion time 8 Animation.durati on = DURATION; 9 10//Set motion Type11 Animation.type = type;12 if (subtype! = nil) {13 14//Set Subclass Animation.subtype = subtype;16}17 18//Set operation Moving speed animation.timingfunction = uiviewanimationoptioncurveeaseinout;20 [View.layer addanimation:animation ForKey: @ "Animation"];22} Code Description: Catransition commonly used properties are as follows: Duration: Setting animation Time Type: The following details the motion type subtype: and Ty PE match use, specify the direction of the movement, the following will be described in detail timingfunction: Animation of the motion trajectory, for the change between the beginning and end of the interpolation calculation, the image point that it determines the rhythm of the animation, such as a uniform change (the same time changes in the same amount                   ) or fast and slow, first slow or slow, then fast and slow. * The beginning and end of the animation, there are five presets for (same as): * Kcamediatimingfunctionlinear linear, that is, constant speed * KcamediaTimingfunctioneasein first slow, fast, quick, slow, kcamediatimingfunctioneaseout, kcamediatimingfuncti.     Oneaseineaseout slow and Slow soon * Kcamediatimingfunctiondefault The actual effect is faster in the middle of the animation. 2. Code encapsulation with UIView block callback for Animation 1 #pragma UIView Implementation Animation 2-(void) Animationwithview: (UIView *) View withanimationtransition: (UI Viewanimationtransition) Transition3 {4 [UIView animatewithduration:duration animations:^{5 [UIView setanimationcurve : uiviewanimationcurveeaseinout];6 [UIView setanimationtransition:transition forview:view cache:YES];7}];8} 3. Change view Background map, easy to switch to observe 1 #pragma to view Add background 2-(void) Addbgimagewithimagename: (NSString *) ImageName3 {4 Self.view.backgroundColor = [Uicolor colorwithpatternimage:[uiimage imagenamed:imagename]];5} two. Call the above method to implement the animation we want 1. We add multiple buttons to the view to give different but ton set different tag values, and then bind the same method in Viewcontroller, click on the different button to achieve different page transition effect. The effect of the control on the storyboard is as follows: 2. Let's start writing the method of clicking the button to call back (1). Defines an enumeration to indicate the type of animation that the button corresponds to, with the code as follows: 1 typedef enum:nsuinteger {2 Fade = 1,//Fade 3 Push,//Push 4 Reveal,//Uncover 5 Movein,//cover 6 cube,//Cube 7 Suckeffect,//Suck 8 oglflip,//Flip 9 rippleeffect,//Ripple P Agecurl,//Page one by one pageuncurl,//Flip the Camerairishollowopen,//Open lens camerairishollowclose,//Off lens curldown,//Next page 15      Curlup,//Flip page on Flipfromleft,///left to flip the flipfromright,//Right to flip the animationtype;     (2), gets the tag value of the button: 1 UIButton *button = sender;2 Animationtype animationtype = Button.tag; (3). Each click button changes the value of subtype, including top, left, bottom, right 1 nsstring *subtypestring; 2 3 switch (_subtype) {4 case 0:5 subtypestring = Kcatransitionfromleft, 6 break, 7 case 1:8 subtypestring = kcatransit Ionfrombottom; 9 break;10 case 2:11 subtypestring = kcatransitionfromright;12 break;13 case 3:14 subtypestring = kCATransitionFromTop;15 break;16 default:17 break;18}19 _subtype + = 1;20 if (_subtype > 3) {_subtype = 0;22} (4), using the switch combined with the upper enumeration to determine the button click on 1 switch (Animationtype) 2 {3//various case, here code below will give 4} 3. Call our encapsulated motion method to achieve animation effect (1), fade effect 1 case fade:2 [self transitio Nwithtype:kcatraNsitionfade withsubtype:subtypestring forview:self.view];3 break;4 (2).      Push effect 1 case push:2 [self transitionwithtype:kcatransitionpush withsubtype:subtypestring forview:self.view];3 break;4 The results are as follows: (3). Unlocking effect: 1 case reveal:2 [self transitionwithtype:kcatransitionreveal withsubtype:subtypestring Forview:sel    F.view];3 break; as follows: (4). Overlay effect 1 case movein:2 [self Transitionwithtype:kcatransitionmovein withsubtype:subtypestring FORVIEW:SELF.VI Ew];3 break;4 as follows: (5). Cube effect 1 case cube:2 [self transitionwithtype:@ "Cube" withsubtype:subtypestring Forview:    Self.view];3 break; The results are as follows: (6). Sucking effect 1 case suckeffect:2 [self transitionwithtype:@ "suckeffect" withsubtype:subtypestring ForView:self.vi      Ew];3 break; The results are as follows: (7). Flip Effect 1 case oglflip:2 [self transitionwithtype:@ "oglflip" withsubtype:subtypestring forview:self.view];3 BR    Eak The figure is as follows: 8. Ripple effect 1 case rippleeffect:2 [self transitionwithtype:@ "rippleeffect" withsubtype:subtypestring forview:self.v IEw];3 break; (9). Page flipping and flip-over effects 1 case pagecurl:2 [self transitionwithtype:@ "Pagecurl" withsubtype:subtypestring forview:self.view];3 Break;4 5 Case Pageuncurl:6 [self transitionwithtype:@ "Pageuncurl" withsubtype:subtypestring forview:self.view];7       Break (10). Camera Open effect 1 case camerairishollowopen:2 [self transitionwithtype:@ "Camerairishollowopen" withsubtype:subtypestring Forview:self.view];3 break;4 5 Case camerairishollowclose:6 [self transitionwithtype:@ "Camerairishollowclose"   Withsubtype:subtypestring forview:self.view];7 break; (11), call the second animation method above encapsulated 1 case curldown:2 [self animationWithView:self.view withanimationtransition: Uiviewanimationtransitioncurldown]; 3 break; 4 5 Case Curlup:6 [self animationWithView:self.view withanimationtransition:uiviewanimationtransitioncurlup]; 7 break; 8 9 Case Flipfromleft:10 [self animationWithView:self.view withanimationtransition: Uiviewanimationtransitionflipfromleft];11 break;12 flipfromright:14 [self AnimationWithView:self.view WITHANIMATIONTRANSITION:UIVIEWANIMATIONTRANSITIONFLIPFROMRIGHT];15 break;

iOS animation effects

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.