The work required to perform an animation is automatically completed by the UIView class, but you still have to notify the view when you want to animate, and you need to wrap the code that changes the property into a block of code.
1.UIView animation specific method of creation
-(void) buttonpressed
{
Swap 2 View locations in the controller
[Self.view exchangesubviewatindex:0 withsubviewatindex:1];
UIView begins animation, the first parameter is the identity of the animation, and the second parameter attaches the application information 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 used after setting the callback method
[UIView setanimationdelegate:self];
Set animation curves to control animation speed
[UIView Setanimationcurve:uiviewanimationcurveeaseinout];
Sets the animation mode and indicates where the animation occurred
[UIView Setanimationtransition:uiviewanimationtransitioncurlup ForView:self.view Cache:yes];
Submit UIView Animation
[UIView commitanimations];
}
-(void) viewdidload
{
[Super Viewdidload];
The main function of the UIView animation to complete 2 attempts to switch the controller
Self.bluecontroller = [[Blueviewcontroller alloc] Initwithnibname:nil Bundle:nil];
Set the size of the navigation controller view 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)];
Insert 2 controller views into the current navigation controller view, Yellowcontroller, and display at the front
[Self.view InsertSubview:self.blueController.view atindex:0];
[Self.view InsertSubview:self.yellowController.view atindex:1];
Create the right button for the navigation controller with the button name next
Add buttonpressed Event
Self.rightbaritem = [[Uibarbuttonitem alloc] initwithtitle:@ "Next" style:uibarbuttonitemstyleplain action : @selector (buttonpressed)];
Add a button to the navigation Controller default 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 this controller, then the animation is not displayed.
Reason: This problem occurs because the system has an animation, system animation and this animation repeated.
Solution:
1. Write an animation in a button event
2. Use the timer.
Areanimationsenabled
Returns a Boolean value that indicates whether the animation is finished.
+ (BOOL) areanimationsenabled
return value
No if the animation ends by returning yes.
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 agent message-This selector is set using the Setanimationwillstartselector: and Setanimationdidstopselector: Method.
Context
Additional application information is used to pass to the animation agent message-this selector uses setanimationwillstartselector: and Setanimationdidstopselector: Method.
Discuss
This value is changed because there are some properties that need to be animated in the animation block. An animation block can be nested. If you do not call in the animation block, then the Setanimation class method does nothing. 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. Animations are not interrupted in a separate thread for all applications. With this method, multiple animations can be implemented. View Setanimationbeginsfromcurrentstate: To learn if you start an animation when another animation is playing.
Layerclass
Returns a layer instance object used by a class to create 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 the view is created 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 starting state 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 in the animation block. Use the Beginanimations:context: Class method to begin using the Commitanimations class method to end an animation block. The default value is No.
Setanimationcurve
:
Sets the curve of animation property changes in an animation block.
+ (void) Setanimationcurve: (Uiviewanimationcurve) curve
Discuss
The animation curve is the relative speed of the animation during operation. This method will not work if you are outward-used in an animation block. 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:
To set the Delay property (in seconds) for an animation in an animation block
+ (void) Setanimationdelay: (nstimeinterval) delay
Discuss
This method is not valid for outward use in an 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 animation message.
+ (void) Setanimationdelegate: (ID) delegate
Parameters
Delegate
You can use the Setanimationwillstartselector: and Setanimationdidstopselector: Methods to set the object that receives the agent 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 ends. The default value is null. This selector must have the signature of the following method: animationfinished: (NSString *) Animationid finished: (BOOL) finished context: (void *) context.
Animationid
An identifier provided by an application. and passed to Beginanimations:context: the same parameters. This argument can be empty.
Finished
If the animation completes before the stop returns Yes;
Context
An optional application content provider. 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 a Commitanimations class method. The default value is null.
Setanimationduration:
To set the duration of an animation in an animation block (in seconds)
+ (void) Setanimationduration: (nstimeinterval) duration
Parameters
Duration
Duration of the 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 animation effects in an animation block are automatically repeated.
+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses
Parameters
Repeatautoreverses
If the animation automatically repeats is yes otherwise it is no.
Discuss
Automatic repetition is when the animation moves forward and starts playing again. Use the Setanimationrepeatcount: Class method to specify when the animation will be automatically replayed. If the repeat number is 0 or outside the animation block it will have 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, 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 a Commitanimations class method. The default animation does not loop.
Setanimationsenabled:
Set whether animation is activated
+ (void) setanimationsenabled: (BOOL) enabled
Parameters
Enabled
If yes, activate the animation; otherwise it's No.
Discuss
Changes to animated properties are ignored when the animation parameters are not activated. The default animation is active.
Setanimationstartdate:
Sets the start time for animation property changes within an animation block
+ (void) Setanimationstartdate: (NSDate *) starttime
Parameters
StartTime
A time to start an 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:
To 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 transitioning.
Cache
If yes, the start and end picture views are rendered once and the frames are created in the animation, otherwise the view is rendered at each frame. For example, caching, you don't need to keep updating in the view change, 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, file from one view to another, and then use a container view of a UIView subclass, as follows:
1.Begin a 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 in the container view. 4. Add a child view to 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 be made with 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 a Commitanimations class method.