#import
"ViewController.h"
@interface ViewController ()
@property ( weak, nonatomic) IBOutlet UIImageView *imageV;
@property ( weak, nonatomic) IBOutlet UIView *testView;
@end
@interface ViewController ()
@property ( weak, nonatomic) IBOutlet UIImageView *imageV;
@property ( weak, nonatomic) IBOutlet UIView *testView;
@end
@implementation ViewController
- (
void)viewDidLoad {
[ super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- ( void)imageViewAnimations
{
// self.imageV.animationImages ;
// self.imageV.animationDuration;
// self.imageV.animationRepeatCount;
}
[ super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- ( void)imageViewAnimations
{
// self.imageV.animationImages ;
// self.imageV.animationDuration;
// self.imageV.animationRepeatCount;
}
1
、步骤动画
- (
void)viewAnimationOne
{
// 开始动画
[ UIView beginAnimations: @"hehe" context: NULL];
// 设置动画属性
[ UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // 设置动画曲线
[ UIView setAnimationDelay: 0]; // 设置动画延迟
[ UIView setAnimationDuration: 2]; // 设置动画总时间
[ UIView setAnimationRepeatAutoreverses: NO]; // 是否返回
[ UIView setAnimationsEnabled: YES];
// 完成要执行的动画
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
// 提交动画
[ UIView commitAnimations];
}
{
// 开始动画
[ UIView beginAnimations: @"hehe" context: NULL];
// 设置动画属性
[ UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // 设置动画曲线
[ UIView setAnimationDelay: 0]; // 设置动画延迟
[ UIView setAnimationDuration: 2]; // 设置动画总时间
[ UIView setAnimationRepeatAutoreverses: NO]; // 是否返回
[ UIView setAnimationsEnabled: YES];
// 完成要执行的动画
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
// 提交动画
[ UIView commitAnimations];
}
//
以下均是封装好的动画
2
、
UIView
动画
2
- (
void)viewAnimationTwo
{
[ UIView animateWithDuration: 1 animations:^{
// 使用 '.' 进行调用的时候,赋值操作中结构体和属性不能再一个语句中出现,但是取值的时候可以
// 所以下边的赋值语句是分开写的( * 重点 * )
CGRect frame = self. imageV. frame;
frame. origin. y += 200; //origin 指的是到父视图( 0,0 )的 x y 方向上的距离
{
[ UIView animateWithDuration: 1 animations:^{
// 使用 '.' 进行调用的时候,赋值操作中结构体和属性不能再一个语句中出现,但是取值的时候可以
// 所以下边的赋值语句是分开写的( * 重点 * )
CGRect frame = self. imageV. frame;
frame. origin. y += 200; //origin 指的是到父视图( 0,0 )的 x y 方向上的距离
self.
imageV.
frame = frame;
//
需要移动的视图
移动变换后的位置
}];
}
}
3
、
UIView
动画
3
- (
void)viewAnimationThree
{
[ UIView animateWithDuration: 1 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画执行完成 ");
[ UIView animateWithDuration: 1 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. x += 100;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画 2 执行完成 ");
}];
}];
{
[ UIView animateWithDuration: 1 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画执行完成 ");
[ UIView animateWithDuration: 1 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. x += 100;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画 2 执行完成 ");
}];
}];
}
UIView
动画
4
- (
void)viewAnimationFour
{
[ UIView animateWithDuration: 1 delay: 1 options: UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画 ok");
}];
}
{
[ UIView animateWithDuration: 1 delay: 1 options: UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @" 动画 ok");
}];
}
5
、弹簧动画
- (
void)viewAnimationFive
{
//Damping :弹簧的阻力大小( 0---1 )
//Velocity :相当于重力加速度( 0----- )
[ UIView animateWithDuration: 1 delay: 0 usingSpringWithDamping: 0.1 initialSpringVelocity: 100 options: UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @"-----");
}];
// [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{
// CGRect frame = self.testView.frame;
// frame.origin.y -= 100;
// frame.size.height += 100;
// self.testView.frame = frame;
// } completion:^(BOOL finished) {
// NSLog(@" 加薪完成 ");
// }];
}
{
//Damping :弹簧的阻力大小( 0---1 )
//Velocity :相当于重力加速度( 0----- )
[ UIView animateWithDuration: 1 delay: 0 usingSpringWithDamping: 0.1 initialSpringVelocity: 100 options: UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
} completion:^( BOOL finished) {
NSLog( @"-----");
}];
// [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.9 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{
// CGRect frame = self.testView.frame;
// frame.origin.y -= 100;
// frame.size.height += 100;
// self.testView.frame = frame;
// } completion:^(BOOL finished) {
// NSLog(@" 加薪完成 ");
// }];
}
6
、关键帧动画
- (
void)keyFrameAnimation
{
[ UIView animateKeyframesWithDuration: 6 delay: 0 options: 0 animations:^{
//startTime :开始动画的时间位置,与动画总时间相关
//relativeDuration :某一帧动画执行的总时间,与总时间相关
//1 (在同一时间内可以同时进行多个动画效果)
[ UIView addKeyframeWithRelativeStartTime: 0.0 relativeDuration: 1/ 3.0 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
}];
//2
[ UIView addKeyframeWithRelativeStartTime: 0.0 relativeDuration: 2/ 3.0 animations:^{
CGRect frame = self. testView. frame;
frame. origin. y -= 200;
self. testView. frame = frame;
}];
//3
[ UIView addKeyframeWithRelativeStartTime: 2/ 3.0 relativeDuration: 1/ 3.0 animations:^{
self. testView. backgroundColor = [ UIColor blackColor];
}];
} completion:^( BOOL finished) {
{
[ UIView animateKeyframesWithDuration: 6 delay: 0 options: 0 animations:^{
//startTime :开始动画的时间位置,与动画总时间相关
//relativeDuration :某一帧动画执行的总时间,与总时间相关
//1 (在同一时间内可以同时进行多个动画效果)
[ UIView addKeyframeWithRelativeStartTime: 0.0 relativeDuration: 1/ 3.0 animations:^{
CGRect frame = self. imageV. frame;
frame. origin. y += 200;
self. imageV. frame = frame;
}];
//2
[ UIView addKeyframeWithRelativeStartTime: 0.0 relativeDuration: 2/ 3.0 animations:^{
CGRect frame = self. testView. frame;
frame. origin. y -= 200;
self. testView. frame = frame;
}];
//3
[ UIView addKeyframeWithRelativeStartTime: 2/ 3.0 relativeDuration: 1/ 3.0 animations:^{
self. testView. backgroundColor = [ UIColor blackColor];
}];
} completion:^( BOOL finished) {
NSLog(
@"
关键帧动画执行完成
");
}];
7
、仿射变换
- (
void)affineAnimations
{
[ UIView animateWithDuration: 1 animations:^{
// 每一种都有两中方法,一种两个参数不能持续,第二种可以持续的变换。
//1 、平移变换
{
[ UIView animateWithDuration: 1 animations:^{
// 每一种都有两中方法,一种两个参数不能持续,第二种可以持续的变换。
//1 、平移变换
CGAffineTransform t = CGAffineTransformMakeTranslation(0, 100);
CGAffineTransform t = CGAffineTransformTranslate(self.imageV.transform, 0, 100);
//2 、旋转变换
CGAffineTransform t = CGAffineTransformMakeRotation(M_PI_2*3);
CGAffineTransform t =
CGAffineTransformRotate(
self.
imageV.
transform,
M_PI_2);
//3 、缩放变换
//3 、缩放变换
CGAffineTransform t = CGAffineTransformMakeScale(0.5, 2);
CGAffineTransform t = CGAffineTransformScale(self.imageV.transform, 0.5, 2);
//4
、仿射变换组
CGAffineTransform t1 = CGAffineTransformRotate(self.imageV.transform, M_PI_2);
CGAffineTransform t2 = CGAffineTransformScale(self.imageV.transform, 0.5, 2);
CGAffineTransform t3 = CGAffineTransformTranslate(self.imageV.transform, 0, 100);
CGAffineTransform tt = CGAffineTransformConcat(t1, t2);
CGAffineTransform t = CGAffineTransformConcat(t3, tt);
// 最后都要添加仿射变换
self. imageV. transform = t;
}];
}