I. Animation of the Transitions
A subclass of Caanimation that is used to animate transitions, providing layers with animations to move out of the screen and move into the screen. iOS has less effect than Mac OS x transitions
Uinavigationcontroller is the animation effect of pushing the controller's view into the screen through catransition
Attribute resolution:
Type: Animation transition types
Subtype: Animation transition Direction
Startprogress: Animation starting point (percentage of overall animation)
Endprogress: Animation Endpoint (percentage of overall animation)
Transitions Animation code example
1. The interface constructs
2. Implementation code
Copy Code code as follows:
//
Yyviewcontroller.m
13-Transitions Animation
//
Created by Apple on 14-6-21.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
@interface Yyviewcontroller ()
@property (nonatomic,assign) int index;
@property (Weak, nonatomic) Iboutlet Uiimageview *iconview;
-(Ibaction) Preonclick: (UIButton *) sender;
-(Ibaction) Nextonclick: (UIButton *) sender;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
Self.index=1;
}
-(Ibaction) Preonclick: (UIButton *) Sender {
self.index--;
if (self.index<1) {
self.index=7;
}
Self.iconview.image=[uiimage imagenamed: [NSString stringwithformat:@ "%d.jpg", Self.index]];
Create a core animation
Catransition *ca=[catransition Animation];
Tell what to do or what animations to perform
Set over effects
ca.type=@ "Cube";
Set the excessive orientation of the animation (left)
Ca.subtype=kcatransitionfromleft
Set the time of the animation
ca.duration=2.0;
Add animation
[Self.iconView.layer ADDANIMATION:CA Forkey:nil];
}
Next one
-(Ibaction) Nextonclick: (UIButton *) Sender {
self.index++;
if (self.index>7) {
Self.index=1;
}
Self.iconview.image=[uiimage imagenamed: [NSString stringwithformat:@ "%d.jpg", Self.index]];
1. Create a core animation
Catransition *ca=[catransition Animation];
1.1 Tell me what animation to perform
1.2 Setting over effects
ca.type=@ "Cube";
1.3 Set the excessive orientation of the animation (right)
Ca.subtype=kcatransitionfromright;
1.4 Setting the animation time
ca.duration=2.0;
1.5 Setting the starting point of the animation
ca.startprogress=0.5;
1.6 Set the end of the animation
ca.endprogress=0.5;
2. Add animation
[Self.iconView.layer ADDANIMATION:CA Forkey:nil];
}
@end
Click on the previous one, or the next one, to show the corresponding animation effect.
Second, group animation
Caanimation, you can save a set of animated objects, after the Caanimationgroup object is added to the layer, all the animation objects in the group can run concurrently
Attribute resolution:
Animations: A nsarray used to hold a set of animated objects
By default, a set of animated objects is run at the same time, or you can change the start time of the animation by setting the BeginTime property of the animation object
Grouping Animation code example
Code:
Copy Code code as follows:
#import "YYViewController.h"
@interface Yyviewcontroller ()
@property (Weak, nonatomic) Iboutlet UIView *iconview;
@end
@implementation Njviewcontroller
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
Panning Animations
Cabasicanimation *a1 = [cabasicanimation animation];
A1.keypath = @ "TRANSFORM.TRANSLATION.Y";
A1.tovalue = @ (100);
Zoom Animation
Cabasicanimation *a2 = [cabasicanimation animation];
A2.keypath = @ "Transform.scale";
A2.tovalue = @ (0.0);
Rotate animation
Cabasicanimation *a3 = [cabasicanimation animation];
A3.keypath = @ "Transform.rotation";
A3.tovalue = @ (m_pi_2);
Group Animation
Caanimationgroup *groupanima = [Caanimationgroup animation];
Groupanima.animations = @[a1, a2, A3];
Set time for group animation
Groupanima.duration = 2;
Groupanima.fillmode = Kcafillmodeforwards;
Groupanima.removedoncompletion = NO;
[Self.iconView.layer Addanimation:groupanima Forkey:nil];
}
@end
Description: Pan-rotate-zoom is performed together as a set of animations.
Execution effect:
Three, UIView package animation
1.UIView Animation (end-to-end)
(1). Simple description
Uikit directly integrates animations into the UIView class, and when some of the internal properties change, UIView provides animation support for these changes
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, for which you need to place the code that changes the property in [UIView Beginanimations:nil Context:nil] and [UIView Commitanimations] Between
Common Method Resolution:
+ (void) Setanimationdelegate: (ID) delegate sets an animation proxy object that sends a message to the proxy object when the animation starts or ends
+ (void) Setanimationwillstartselector: (SEL) selector executes the selector of the delegate object when the animation is about to begin, and Beginanimations:context: The arguments passed in are passed into the selector
+ (void) Setanimationdidstopselector: (SEL) selector When the animation ends, executes the selector of the delegate object and Beginanimations:context: The arguments passed in are passed into the selector
+ (void) Setanimationduration: (nstimeinterval) duration animation duration, in seconds
+ (void) Setanimationdelay: (nstimeinterval) delay animation delay delay seconds before starting
+ (void) Setanimationstartdate: (NSDate *) StartDate the start time of the animation, which defaults to now
+ (void) Setanimationcurve: (Uiviewanimationcurve) curve animation Rhythm Control
+ (void) Setanimationrepeatcount: (float) repeatcount Repeat number of animations
+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses if set to Yes, the effect of each repeated execution of the animation will be the opposite
+ (void) Setanimationtransition: (uiviewanimationtransition) Transition Forview: (UIView *) View cache: (BOOL) cache Sets the transition effect for view views, transition Specifies the transition type, and the cache setting yes represents a good performance with the view cache
(2). code example
Copy Code code as follows:
//
Yyviewcontroller.m
01-uiview Package Animation
//
Created by Apple on 14-6-22.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
@interface Yyviewcontroller ()
@property (Weak, nonatomic) Iboutlet UIView *customview;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) viewdidload
{
[Super Viewdidload];
}
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
Print the position of an animation block
NSLog (@ "position before animation execution:%@", Nsstringfromcgpoint (Self.customView.center));
End-end Animation
[UIView Beginanimations:nil Context:nil];
Perform animation
Set animation Execution Time
[UIView setanimationduration:2.0];
Set up agents
[UIView setanimationdelegate:self];
Set the event that the animation has finished calling
[UIView setanimationdidstopselector: @selector (didstopanimation)];
Self.customview.center=cgpointmake (200, 300);
[UIView commitanimations];
}
-(void) didstopanimation
{
NSLog (@ "Animation execution completed");
Print the position of an animation block
NSLog (@ "Position after animation execution:%@", Nsstringfromcgpoint (Self.customView.center));
}
@end
Execution results:
To print the position of an animation block:
(3). The contrast between animation of UIView package and Calayer animation
Animation can be achieved with both UIView and Calayer, but in real-world development, the UIView-encapsulated animation is mostly used, and calayer animations are rarely used.
The difference between Calayer core animation and UIView animation:
The UIView package will not rebound after the animation has finished executing. That is, if you change the position of the layer through the Calayer core animation, it looks as though it has changed, but in fact its position is unchanged.
code example:
Copy Code code as follows:
//
Yyviewcontroller.m
01-uiview Package Animation
//
Created by Apple on 14-6-22.
Copyright (c) 2014 itcase. All rights reserved.
//
#import "YYViewController.h"
@interface Yyviewcontroller ()
@property (Weak, nonatomic) Iboutlet UIView *customview;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
//1. Create a core animation
cabasicanimation *anima=[cabasicanimation Animation];
//translation
anima.keypath=@ "position";
//Set animation for execution
& nbsp; Anima.tovalue=[nsvalue Valuewithcgpoint:cgpointmake (200, 300)];
/Set time to perform animation
anima.duration=2.0;
//Set animation does not delete after the animation
anima.removedoncompletion=no;
// Sets the latest status for saving animations
anima.fillmode=kcafillmodeforwards
// anima.fillmode= Kcafillmodebackwards;
//Set agent for animation
anima.delegate=self;
//2. Add Core animation
[Self.customView.layer Addanimation:anima Forkey:nil];
}
-(void) Animationdidstart: (caanimation *) Anim
{
Print the position of an animation block
NSLog (@ "position before animation starts:%@", Nsstringfromcgpoint (Self.customView.center));
NSLog (@ "position before animation starts:%@", Nsstringfromcgpoint (self.customView.layer.position));
}
-(void) Animationdidstop: (Caanimation *) Anim finished: (BOOL) flag
{
Print the position of an animation block
NSLog (@ "Position after animation execution:%@", Nsstringfromcgpoint (self.customView.layer.position));
}
@end
Print results:
2, block animation
(1). Simple description
Copy Code code as follows:
+ (void) Animatewithduration: (nstimeinterval) Duration delay: (nstimeinterval) Delay options: (uiviewanimationoptions) Options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished) completion
Parameter resolution:
Duration: Duration of animation
Delay: Animation delay delay seconds to begin
Options: The rhythm control of animation
Animations: Put the code that changes the View property in this block
Completion: This block is automatically invoked when the animation is finished
Transitions Animation
Copy Code code as follows:
+ (void) Transitionwithview: (UIView *) View Duration: (nstimeinterval) Duration options: (uiviewanimationoptions) Options animations: (void (^) (void)) animations completion: (void (^) (BOOL finished) completion
Parameter resolution:
Duration: Duration of animation
View: Views that need to be animated for transitions
Options: type of transitions animation
Animations: Put the code that changes the View property in this block
Completion: This block is automatically invoked when the animation is finished
Copy Code code as follows:
+ (void) Transitionfromview: (UIView *) Fromview Toview: (UIView *) Toview Duration: (nstimeinterval) Duration options: ( uiviewanimationoptions) Options Completion: (void (^) (BOOL finished)) completion
After the method call completes, the following two lines of code are executed:
Copy Code code as follows:
Add Toview to Parent view
[Fromview.superview Addsubview:toview];
Remove the Fromview from the parent view
[Fromview.superview Removefromsuperview];
Parameter resolution:
Duration: Duration of animation
Options: type of transitions animation
Animations: Put the code that changes the View property in this block
Completion: This block is automatically invoked when the animation is finished
(2). code example
Copy Code code as follows:
#import "YYViewController.h"
@interface Yyviewcontroller ()
@property (Weak, nonatomic) Iboutlet UIView *customview;
@end
Copy Code code as follows:
@implementation Yyviewcontroller
-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
{
Blocks code block animation
[UIView transitionWithView:self.customView duration:3.0 options:0 animations:^{
Animation to perform
NSLog (@ "position before animation starts:%@", Nsstringfromcgpoint (Self.customView.center));
Self.customview.center=cgpointmake (200, 300);
} completion:^ (BOOL finished) {
First action after animation is finished
NSLog (@ "Animation execution completed");
NSLog (@ "Position after animation execution:%@", Nsstringfromcgpoint (Self.customView.center));
}];
}
@end
Print results:
Tip: Self.customView.layer.position and self.customView.center are equivalent because the default value for position is (0.5,0.5).
3, supplementary
(1). Frame animation for Uiimageview
Uiimageview can make a series of pictures appear in order in a specific time
Related attribute resolution:
Animationimages: Picture to display (a nsarray with UIImage)
Animationduration: The time required to fully display all the pictures in animationimages
Animationrepeatcount: The number of times the animation is executed (default is 0, representing an infinite loop)
Related method Resolution:
-(void) startanimating; Start animation
-(void) stopanimating; Stop animation
-(BOOL) isanimating; Whether the animation is running
(2). Uiactivityindicatorview
is a rotational progress wheel that can be used to tell the user that an operation is in progress, typically initialized with Initwithactivityindicatorstyle
Method Resolution:
-(void) startanimating; Start animation
-(void) stopanimating; Stop animation
-(BOOL) isanimating; Whether the animation is running
Uiactivityindicatorviewstyle has 3 values to choose from:
Copy Code code as follows:
Uiactivityindicatorviewstylewhitelarge//Large white indicator
Uiactivityindicatorviewstylewhite//Standard size white indicator
Uiactivityindicatorviewstylegray//Gray indicator, for white background