IOS animation Summary-uiview Animation

Source: Internet
Author: User

1. Overview

Uikit directly integrates the animation into the uiview class to create a simple animation. The uiview class defines several attribute declarations that support animations internally. When these attributes change, the view provides built-in animation support for the change process.

The work required to execute an animation is automatically completed by the uiview class, but you still need to notify the view when you want to execute the animation. To do this, you need to wrap the code for changing attributes into a code block.

2. How to Create a uiview Animation

-(Void) buttonpressed
{
// Switch the two view locations in the current view Controller
[Self. View exchangesubviewatindex: 0 withsubviewatindex: 1];
// Uiview starts the animation. The first parameter is the animation identifier, and the second parameter is used to transmit the application information to the animation proxy.
[Uiview beginanimations: @ "view flip" context: Nil];
// Animation duration
[Uiview setanimationduration: 1.25];
// Sets the animation callback function. You can use the callback method after setting it.
[Uiview setanimationdelegate: Self];
// Set the animation curve to control the animation speed
[Uiview setanimationcurve: uiviewanimationcurveeaseinout];
// Set the Animation Mode and specify the animation location
[Uiview setanimationtransition: uiviewanimationtransitioncurlup forview: Self. View cache: Yes];
// Submit the uiview animation.
[Uiview commitanimations];
}

-(Void) viewdidload
{
[Super viewdidload];
// The main function is to use the uiview animation to switch between two controllers.

Self. bluecontroller = [[blueviewcontroller alloc] initwithnibname: Nil Bundle: Nil];
// Set the size of the navigation controller View to 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)];
// Insert the two controller views to the current navigation controller view. Insert the yellowcontroller and display it at the beginning.
[Self. View insertsubview: Self. bluecontroller. View atindex: 0];
[Self. View insertsubview: Self. yellowcontroller. View atindex: 1];
// Create the right button of the navigation controller. The button name is "Next ".
// Add a buttonpressed event
Self. rightbaritem = [[uibarbuttonitem alloc] initwithtitle: @ "Next" style: uibarbuttonitemstyleplain target: Self action: @ selector (buttonpressed)];
// Add the button to the default right button of the navigation Controller
Self. navigationitem. rightbarbuttonitem = self. rightbaritem;
}

There is a problem: If the animation is not placed in the button event and directly placed in viewdidload, the program first executes this controller, and the animation will not be displayed.

Cause: this problem occurs because the system has an animation when it is started, and the system animation and the animation are repeated.

Solution:

1. Write the animation in the button event

2. Use a timer.

Turn: uiview animation more detailed explanation; http://wsqwsq000.iteye.com/blog/1189183

Areanimationsenabled

Returns a Boolean value indicating whether the animation ends.
+ (Bool) areanimationsenabled
Return Value
If the animation ends, yes is returned; otherwise, no is returned.

 

Beginanimations: context:

Start an animation Block
+ (Void) beginanimations :( nsstring *) animationid context :( void *) Context
Parameters
Animationid
The internal application identifier of the animation block is used to pass the message to the animation proxy-This selector is set using setanimationwillstartselector: And setanimationdidstopselector.
Context
The additional application information is used to pass the message to the animation proxy-This selector uses setanimationwillstartselector: And setanimationdidstopselector: method.
Discussion
This value is changed because some attributes that need to be generated in the animation block are set. Animation blocks can be nested. If it is not called in an animation block, the setanimation class method will do nothing. Use beginanimations: Context: to start an animation block and use the commitanimations class method to end an animation block.

Commitanimations

End an animation block and start when it is outside the animation block.
+ (Void) commitanimations
Discussion
If the current animation block is the outermost animation block, the animation block starts when the application returns to the loop. All applications of an animation in an independent thread will not be interrupted. With this method, multiple animations can be implemented. View the setanimationbeginsfromcurrentstate: to learn if an animation starts when another animation is playing.

Layerclass

The returned class is used to create a layer instance object of this class.
+ (Class) layerclass
Return Value
A class used to create a view layer
Discussion
Override subclass to specify a custom class for display. Called when creating a view layer. The default value is a calayer class object.

Setanimationbeginsfromcurrentstate
:
Set the animation to start playing from the current status.
+ (Void) setanimationbeginsfromcurrentstate :( bool) fromcurrentstate
Parameters
Fromcurrentstate
Yes if the animation needs to be played from their current status. Otherwise, it is no.
Discussion
If it is set to yes, when the animation is running, the current view position will be used as the starting state of the new animation. If it is set to no, the new animation uses the position of the last state of the view as the start state before the current animation ends. This method will not do anything if the animation is not running or not called outside the animation block. Use beginanimations: Context: Class Method to start and use the commitanimations class method to end the animation block. The default value is no.

Setanimationcurve
:
Set the curve of the animation attribute change in the animation block.
+ (Void) setanimationcurve :( uiviewanimationcurve) curve
Discussion
The animation curve is the relative speed during the animation operation. This method will be invalid if it is called outside the animation block. Use beginanimations: Context: Class Method to start an animation block and use commitanimations to end the animation block. The default animation curve value is uiviewanimationcurveeaseinout.

 

Setanimationdelay:

Set the animation delay attribute in the animation block (in seconds)
+ (Void) setanimationdelay :( nstimeinterval) Delay
Discussion
This method is invalid when it is called outside the animation block. Use beginanimations: Context: Class Method to start an animation block and use the commitanimations class method to end the animation block. The default animation delay is 0.0 seconds.

 

Setanimationdelegate:

Sets the animation message proxy.
+ (Void) setanimationdelegate :( ID) Delegate
Parameters
Delegate
You can use setanimationwillstartselector: And setanimationdidstopselector: to set the object for receiving proxy messages.
Discussion
This method has no effect on the animation block. Use beginanimations: Context: Class Method to start an animation block and use the commitanimations class method to end an animation block. The default value is nil.

 

Setanimationdidstopselector:

Set the message to the animation proxy when the animation is stopped.
+ (Void) setanimationdidstopselector :( SEL) Selector
Parameters
Selector
Send the animation to the animation proxy when the animation ends. The default value is null. The selector must have the signature of the following method: animationfinished :( nsstring *) animationid finished :( bool) finished context :( void *) context.
Animationid
The identifier provided by an application. Same as beginanimations: context. This parameter can be blank.
Finished
If the animation is completed before it is stopped, yes is returned; otherwise, no is returned.
Context
An optional application content provider. Same as beginanimations: Context: method. It can be null.
Discussion
This method has no effect on the animation block. Use 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 the animation block (in seconds)
+ (Void) setanimationduration :( nstimeinterval) Duration
Parameters
Duration
The duration of an animation.
Discussion
This method has no effect on the animation block. Use beginanimations: Context: Class Method to start an animation block and use the commitanimations class method to end an animation block. The default value is 0.2.

 

Setanimationrepeatautoreverses:
Set whether the animation effect in the animation block is automatically replayed.
+ (Void) setanimationrepeatautoreverses :( bool) repeatautoreverses
Parameters
Repeatautoreverses
If the animation is automatically repeated, yes is used; otherwise, no is used.
Discussion
Auto-repeat indicates that the animation starts playing again after the playback ends. Use setanimationrepeatcount: Class Method to specify the automatic animation replay time. If the number of duplicates is 0 or outside the animation block, there will be no effect. Use beginanimations: Context: Class Method to start an animation block and use the commitanimations method to end an animation block. The default value is no.

 

Setanimationrepeatcount:

Set the number of repetitions of an animation in the animation module.
+ (Void) setanimationrepeatcount :( float) repeatcount
Parameters
Repeatcount
Number of animation repetitions. This value can be a score.
Discussion
This attribute has no effect on the animation block. Use beginanimations: Context: Class Method to start an animation block and end with the commitanimations class method. The default animation does not rotate.

 

Setanimationsenabled:
Set whether to activate the animation
+ (Void) setanimationsenabled :( bool) Enabled
Parameters
Enabled
If yes, activate the animation; otherwise, no.
Discussion
When the animation parameter is not activated, the animation attribute changes will be ignored. The animation is activated by default.

 

Setanimationstartdate:
Set the start time of the animation attribute change within the animation block.
+ (Void) setanimationstartdate :( nsdate *) starttime
Parameters
Starttime
Start time of an animation
Discussion
Use beginanimations: Context: Class Method to start an animation block and use the commitanimations class method to end the animation block. The default start time value is returned by the cfabsolutetimegetcurrent method.

 

Setanimationtransition: forview: cache:
Set transition for the view in the animation Block
+ (Void) setanimationtransition :( uiviewanimationtransition) transition forview :( uiview *) View cache :( bool) Cache
Parameters
Transition
Apply a transition effect to the view. Possible values are defined in uiviewanimationtransition.
View
View object to be transitioned.
Cache
If yes, rendering the Image view at the beginning and end and creating frames in the animation; otherwise, the view is rendered at each frame. For example, you do not need to update the view continuously during the view transition. You only need to wait until the conversion is complete before updating the view.
Discussion
If you want to change the appearance of a view during the transformation process. For example, the file uses the container view of a uiview subclass from one view to another, as shown below:
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 conversion in the container view. 3. Remove the child view from the container view. 4. Add a sub-View to the container view. 5. End the animation block.

 

Setanimationwillstartselector:

Send a message to the animation proxy when the animation starts.
+ (Void) setanimationwillstartselector :( SEL) Selector
Parameters
Selector
Send messages to the animation agent before the animation starts. The default value is null. This selector must have the same parameters as beginanimations: Context: method, an optional program identifier and content. All these parameters can be nil.
Discussion
This method has no effect on the animation block. Use beginanimations: Context: Class Method to start an animation block and end with the commitanimations class method.

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.