Turn-ios Animation summary----UIView animation

Source: Internet
Author: User

From: http://blog.csdn.net/huifeidexin_1/article/details/7597868/

1. Overview

Uikit integrates animations directly into the UIView class, enabling the creation of simple animations. The UIView class defines several intrinsic animation-enabled property declarations that, when changed, provide built-in animation support for their changing process.

The work required to perform the animation is done automatically by the UIView class, but you still want to notify the view when you want to perform the animation, and you need to wrap the code that alters the property into a block of code.

How to create a 2.UIView animation

-(void) buttonpressed
{
Swap 2 View positions in the View controller
[Self.view exchangesubviewatindex:0 withsubviewatindex:1];
UIView begins the animation, the first parameter is the identity of the animation, and the second parameter attaches the application information used to pass to the animation agent message
[UIView beginanimations:@ "View Flip" context:nil];
Animation duration
[UIView setanimationduration:1.25];
Sets the callback function for the animation, which can be set using the callback method
[UIView setanimationdelegate:self];
Set animation curves to control animation speed
[UIView Setanimationcurve:uiviewanimationcurveeaseinout];
Animate and indicate where the animation occurred
[UIView Setanimationtransition:uiviewanimationtransitioncurlup ForView:self.view Cache:yes];
Submit UIView Animations
[UIView commitanimations];
}

-(void) viewdidload
{
[Super Viewdidload];
Main function through UIView Animation 2 attempts to switch the controller

Self.bluecontroller = [[Blueviewcontroller alloc] Initwithnibname:nil Bundle:nil];
Set the navigation controller view size to occupy the entire screen
[Self.blueController.view setframe:cgrectmake (0, 0, Self.view.frame.size.width, self.view.frame.size.height)];

Self.yellowcontroller = [[Yellowcontroller alloc]initwithnibname:nil Bundle:nil];
[Self.yellowController.view setframe:cgrectmake (0, 0, Self.view.frame.size.width, self.view.frame.size.height)];
Inserts 2 controller views into the current navigation controller view, Yellowcontroller, and appears at the front
[Self.view InsertSubview:self.blueController.view atindex:0];
[Self.view InsertSubview:self.yellowController.view atindex:1];
Create navigation Controller Right button, button named Next
Add buttonpressed Event
Self.rightbaritem = [[Uibarbuttonitem alloc] initwithtitle:@ "Next" Style:uibarbuttonitemstyleplain target:self action : @selector (buttonpressed)];
Add a button to the navigation controller by default on the right button
Self.navigationItem.rightBarButtonItem = Self.rightbaritem;
}

There is a problem: if the animation is not placed in the button event, directly into the Viewdidload, the program first executes the controller, then the animation will not be displayed.

Cause: This problem occurs because the system has an animation, system animation and this animation is repeated.

Solution:

1. Write an animation in a button event

2. Use the timer.

Turn: UIView animation more specific explanation; http://wsqwsq000.iteye.com/blog/1189183

Areanimationsenabled

Returns a Boolean value that indicates whether the animation ended.
+ (BOOL) areanimationsenabled
return value
If the end of the animation returns Yes, otherwise No.

Beginanimations:context:

Start an animation block
+ (void) Beginanimations: (NSString *) Animationid context: (void *) context
Parameters
Animationid
The animation block internal application identity is used to pass to the animation proxy message-This selector applies setanimationwillstartselector: And Setanimationdidstopselector: Method to set.
Context
Additional application information is used to pass to the animation proxy message-this selector uses setanimationwillstartselector: and Setanimationdidstopselector: Method.
Discuss
This value is changed because you have set some properties that need to animate in the animation block. Animation blocks can be nested. The Setanimation class method does nothing if it is not called in the animation block. Use Beginanimations:context: To start an animation block and end an animation block with the Commitanimations class method.


Commitanimations

Ends an animation block and starts when he is outside the animation block.
+ (void) commitanimations
Discuss
If the current animation block is the outermost animation block, the animation block starts when the application returns to the loop run time. Animations are not interrupted in a separate thread for all applications. With this method, multiple animations can be implemented. View Setanimationbeginsfromcurrentstate: To understand if you start an animation when another animation is playing.


Layerclass

The return class is used to create a layer instance object of this class.
+ (Class) layerclass
return value
A class to create the view layer
Discuss
Overrides subclasses to specify a custom class to display. Called when creating a view layer. The default value is the Calayer class object.


Setanimationbeginsfromcurrentstate
:
Sets the animation to start playing from the current state.
+ (void) Setanimationbeginsfromcurrentstate: (BOOL) fromcurrentstate
Parameters
Fromcurrentstate
Yes if the animation needs to start playing from their current state. Otherwise, No.
Discuss
If set to Yes then when the animation is running, the position of the current view will be the beginning of the new animation. If set to No, the new animation will use the position of the last state of the view as the starting state before the end of the current animation. This method will not do anything if the animation is not running or is not being used out of the animation block. Use the Beginanimations:context: Class method to begin using the Commitanimations class method to end the animation block. The default value is No.


Setanimationcurve
:
Sets the curve of the animation property change in the animation block.
+ (void) Setanimationcurve: (Uiviewanimationcurve) curve
Discuss
The animation curve is the relative speed of the animation during the run. This method will not work if the animation block is out of the way. Use the Beginanimations:context: Class method to start the animation block and end the animation block with Commitanimations. The value of the default animation curve is uiviewanimationcurveeaseinout.

Setanimationdelay:

Set the Delay property (in seconds) of an animation in an animation block
+ (void) Setanimationdelay: (nstimeinterval) delay
Discuss
This method is not valid for an out of animation block. Use the Beginanimations:context: Class method to start an animation block and end the animation block with the Commitanimations class method. The default animation delay is 0.0 seconds.

Setanimationdelegate:

Sets the agent for the animated message.
+ (void) Setanimationdelegate: (ID) delegate
Parameters
Delegate
You can use the Setanimationwillstartselector: and Setanimationdidstopselector: Method to set the object that receives the proxy message.
Discuss
This method has no effect outside the animation block. Use the Beginanimations:context: Class method to start an animation block and end an animation block with the Commitanimations class method. The default value is nil

Setanimationdidstopselector:

Sets the message to the animation agent when the animation stops.
+ (void) Setanimationdidstopselector: (SEL) Selector
Parameters
Selector
Sent to the animation agent when the animation is finished. The default value is null. This selector must be signed with the following method: animationfinished: (NSString *) Animationid finished: (BOOL) finished context: (void *) context.
Animationid
An application-supplied identifier. and passed to Beginanimations:context: the same parameters. This parameter can be empty.
Finished
Returns yes if the animation finishes before it stops, otherwise it is no.
Context
An optional provider of application content. and Beginanimations:context: The same parameters as the method. can be empty.
Discuss
This method has no effect outside the animation block. Use the Beginanimations:context: Class method to start an animation block and end with the Commitanimations class method. The default value is null.

Setanimationduration:

Set the animation duration (in seconds) in an animation block
+ (void) Setanimationduration: (nstimeinterval) duration
Parameters
Duration
The duration of a period of animation.
Discuss
This method has no effect outside the animation block. Use the Beginanimations:context: Class method to start an animation block and end an animation block with the Commitanimations class method. The default value is 0.2.

Setanimationrepeatautoreverses:
Sets whether the animation effect in the animation block repeats itself automatically.
+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses
Parameters
Repeatautoreverses
If the animation repeats automatically it is yes or No.
Discuss
Auto-Repeat is when the animation starts playing back and forth. Use the Setanimationrepeatcount: Class method to specify when the animation will be automatically replayed. If the number of repetitions is 0 or outside the animation block, there will be no effect. Use the Beginanimations:context: Class method to start an animation block and end an animation block with the Commitanimations method. The default value is No.

Setanimationrepeatcount:

Set the number of repetitions of an animation in an animation module
+ (void) Setanimationrepeatcount: (float) repeatcount
Parameters
RepeatCount
The number of times the animation repeats, and this value can be a fraction.
Discuss
This property has no effect outside the animation block. Use the Beginanimations:context: Class method to start an animation block and end it with the Commitanimations class method. The default animation does not loop.

Setanimationsenabled:
Set whether animations are activated
+ (void) setanimationsenabled: (BOOL) enabled
Parameters
Enabled
If yes, activate the animation;
Discuss
Changes to the animated properties are ignored when the animation parameters are not activated. The default animation is activated.

Setanimationstartdate:
Sets the start time of the animation property change within the animation block
+ (void) Setanimationstartdate: (NSDate *) startTime
Parameters
StartTime
A time to start the animation
Discuss
Use the Beginanimations:context: Class method to start an animation block and end the animation block with the Commitanimations class method. The default start time value is returned by the Cfabsolutetimegetcurrent method.


SetAnimationTransition:forView:cache:
Set a transition for a view in an animation block
+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache
Parameters
Transition
Apply a transition effect to the view. The possible values are defined in uiviewanimationtransition.
View
The view object that needs to be transitioned.
Cache
If yes, renders at the beginning and end of the picture view once and creates frames in the animation, otherwise the view will be rendered at each frame. For example, you don't need to keep updating the view transitions, you just have to wait until the conversion is complete before you update the view.
Discuss
If you want to change the appearance of the view during the transition. For example, a file from one view to another view, and then use a container view of the UIView subclass, as follows:
1.Begin an animation block.
2.Set the transition on the container view.
3.Remove the Subview from the container view.
4.Add the new Subview to the container view.
5.Commit the animation block.
1. Start an animation block. 2. Set the transformation in the container view. 3. Remove the child view in the container view. 4. Add a child view in the container view. 5. End the animation block.

Setanimationwillstartselector:

Send a message to the animation agent when the animation starts
+ (void) Setanimationwillstartselector: (SEL) Selector
Parameters
Selector
Sends a message to the animation agent before the animation begins. The default value is null. This selector must consist of the same parameters as the Beginanimations:context: method, an optional program identifier and content. These parameters can all be nil.
Discuss
This method has no effect outside the animation block. Use the Beginanimations:context: Class method to start an animation block and end it with the Commitanimations class method.

Turn-ios Animation summary----UIView animation

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.