IOS7 Custom Animation Jumps

Source: Internet
Author: User

Brief introduction

In the iOS7 system, you'll find such a detail if you use text messages or AppStore Apple's native tools. The push in the Uinavigationviewcontroller interface is no longer the left side of the old interface like IOS6, the new interface slides directly to the right, but the new view is slid from the right and is covered by the previous view controller. You can also swipe through gestures at the left edge of the interface to jump to the previous interface. 1.1,1.2.


Fig. 1.1 Fig. 1.2

I wonder if you've seen the difference between the two pictures. There is a good news to tell you that in iOS7, all and such similar functions can be implemented by using the IOS7 new APIs to customize the attempt to jump the controller.

A custom jump:

When you click a button in an app, a view controller that will be rendered will slide up at the bottom of the current view. This time, we will implement a custom transformation for the view that needs to be rendered.

Implementing a custom jump in iOS requires the following three steps:

1. Create an animation controller

The first step is to create a class that implements the Uiviewcontrolleranimatedtransitioning protocol. The code contained in this class is the animation to be performed, so this class is called the animation controller.

2. Before rendering a new view controller, set a delegate for the jump.

You need to set up an animated jump delegate for the view controller that you are going to render. This delegate callback gets the animation controller that will execute itself when the new view controller is rendered.

3. Return the animation controller in the callback.

Use the callback method (2) to return an instance of the animation controller you created (1).

Then implement the first step in all the steps: Implement an animation controller.

Create an animation controller

Create a new inherit from NSObject and follow uiviewcontrolleranimatedtransitioning

The class of the Protocol. The uiviewcontrolleranimatedtransitioning protocol must implement two methods for defining custom animations between view controllers.

@interface Custompresentanimationcontroller: NSObject < uiviewcontrolleranimatedtransitioning >

@end

Add the two methods that must be implemented in the. m file:

1. Control the time that is required to perform the entire hop-and-roll drawing. The example code executes in the time set for two seconds.

-(nstimeinterval) Transitionduration:
(ID <uiviewcontrollercontexttransitioning>) transitioncontext {

return 2.0 ;

}

2. The method parameter Transitioncontext can help you to obtain the view controller, the content view and a small number of other ins and outs before and after the jump. You can traverse these properties and rely on the included view controller to make your jump animations unique.

-(void) animatetransition:
(ID <uiviewcontrollercontexttransitioning>) transitioncontext {

1. Obtain State from the context

Uiviewcontroller *toviewcontroller = [Transitioncontext viewcontrollerforkey: Uitransitioncontexttoviewcontrollerkey];

CGRect finalframe = [Transitioncontext finalframeforviewcontroller: Toviewcontroller];

2. Obtain the container view

UIView *containerview = [Transitioncontext containerview];

3. Set initial state

CGRect screenbounds = [[uiscreenmainscreen]bounds]; toviewcontroller. View . Frame =

Cgrectoffset (finalframe,0, screenbounds. size . Height ); //4. Add the View

[Containerviewaddsubview: Toviewcontroller. View ];

5. Animate

nstimeintervalduration =
[ self transitionduration: Transitioncontext];

[UIViewanimatewithduration:d uration animations: ^{

Toviewcontroller. View. frame= finalframe; } Completion: ^ (BOOLfinished) {

6. Inform the context of completion

[Transitioncontext completetransition:YES];

}];

}

Click to follow me, more exciting content!!!

Group number: 336146073

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.