Switch between different view controllers under the iOS dev-24 navigation controller: Use the layer layer of catrasition and view for custom animation effects

Source: Internet
Author: User

(1) The animation effect here refers to the interface switch animation effect, we often fade in and out, right out of exiting and so on, of course, there are some advanced animation, this animation suitable for the game class, for the general app will appear too fancy.


(2) We do not add any framework (Quartzcore) here or import any header files (QuartzCore.h), you can create an object, such as Animation1, directly with Catransiton (the subclass of Caanimation).


(3) After the creation, we will animate this animation object, which is mainly related to the type attribute, and there are two values: one is to call the system comes with some effects, kcatransition beginning, such as Animation1.type= Kcatransitionpush, Kcatransitionmovein, Kcatransitionfade, etc. the other is the method of passing in the name, which is also built-in, in a certain library (is it in the QuartzCore.h?). , no matter how much, it can be directly used @ "" To assign values, such as [email protected] "cube", @ "Pagecurl", @ "Rippleeffect" and so on.


(4) Of course, the most important when we are the animation effect is on the navigation controller view layer, so to display this animation, we have to load it, that is, directly assigned to the value, such as [Self.navigationController.view.layer Addanimation:animation1 Forkey:nil];


(5) Another important thing is to close our system default animation, [Self.navigationcontroller Popviewcontrolleranimated:no], that is, set to NO, to prevent the appearance of strange animation overlay.


We are still talking about this in the navigation controller, so of course we need to create 2 view controllers to be placed in the navigation controller for use when the interface jumps (switches).


This is the root attempt controller viewcontroller.m file, the core part is relatively simple, three steps.

#import "ViewController.h" #import "SecondViewController.h" @interface Viewcontroller () @end @implementation    viewcontroller-(void) Viewdidload {//UIButton *btn1=[uibutton Buttonwithtype:uibuttontyperoundedrect];    Btn1.backgroundcolor=[uicolor Whitecolor];    Btn1.frame=cgrectmake (38, 80, 300, 30);    [Btn1 settitle:@ "Jump to SECOND" forstate:uicontrolstatenormal];    [Btn1 addtarget:self Action: @selector (Jumpto) forcontrolevents:uicontroleventtouchupinside];    [Self.view ADDSUBVIEW:BTN1];    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.}    -(void) jumpto{Secondviewcontroller *second1=[[secondviewcontroller Alloc]init]; Three simple Steps (1) Instantiate a Transform animation object Animation2 (2) sets an animation Pagecurl (3) Loads the animated object onto the layer layer of the navigation controller view Catransition *animation2=[    Catransition Animation];    [email protected] "oglflip";    [Self.navigationController.view.layer Addanimation:animation2 Forkey:nil]; Of course, we need to turn off the default animation, <span style= "font-family:arial, Helvetica,Sans-serif; " > Although some animations are not affected, some will overlap with the default animation </span> [Self.navigationcontroller pushviewcontroller:second1 animated:no];} @end

Here is the secondviewcontroller.m file for the sub-page:

#import "SecondViewController.h" @interface Secondviewcontroller () @end @implementation secondviewcontroller-(void) Viewdidload {//Uibarbuttonitem *barbtn1=[[uibarbuttonitem alloc]initwithtitle:@ "Home" Style:uibarbuttonitemstyleplai    N target:self Action: @selector (Backto)];    SELF.NAVIGATIONITEM.LEFTBARBUTTONITEM=BARBTN1;    Self.view.backgroundcolor=[uicolor Purplecolor];    [Super Viewdidload]; Do any additional setup after loading the view.} -(void) backto{//The default animation effect is: from right to left, go back from left to right//either way, first create a toggle object that is Catransition object Catransition *animation1=[catransit    Ion animation];    Then set the time to switch, that is, the time animation1.duration=1 animation; Here are the plays, there are several ways to set the type of animation//First is: With the default type and subtype to set the system comes with, there are 7, 8 kinds of simple basic, but seemingly subtype still invalid, in short, with the type to set the system comes with 8 kinds of enough/from up and down around    , as well as fade, Movein, Push, reveal and so on 8 kinds of simple animation1.type=kcatransition;        Animation1.subtype=kcatransitionpush; The second way, defined directly by the name, does this need to be supported by the Quartzcore framework? Xcode6 seems to have been configured, do not need to import any header files, and this effect will cover the first use of the above 8 default simple animation//such as Cube, Rippleeffect, SuckeffECT, Oglflip, Pagecurl, Pageuncurl [email protected] "oglflip"; After the animation is set, it is the time to set the animation, that is, the display and exit effects such as fade and so on//seemingly no effect, and can still omit to write [Animation1 settimingfunction:[camediatimingfunction    Functionwithname:kcamediatimingfunctioneaseineaseout]];    The most important step is to load this animation into the view layer of the navigation controller [Self.navigationController.view.layer Addanimation:animation1 Forkey:nil]; The default animation is turned off, although some animations are not affected, but some will overlap with the default animation [Self.navigationcontroller Popviewcontrolleranimated:no];}    -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

The animation effect is not obvious, recorded with Licecap.


Switch between different view controllers under the iOS dev-24 navigation controller: Use the layer layer of catrasition and view for custom animation effects

Related Article

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.