动画实现集合

iOS核心动画笔记

2015-11-25  本文已影响240人  _浅墨_
  1. "小画板程序"
    完成"小画板"程序。

下载地址:
http://git.oschina.net/changyou/mySmallPainter/repository/archive/master

git链接 :
https://git.oschina.net/changyou/mySmallPainter.git

  1. CALayer介绍
    2.1. CALayer
    2.1 CALayer的常见属性
// "阴影"效果(shadowColor、shadowOffset、shadowOpacity属性需要同时设置后才可以看到)
// 设置"阴影"的颜色, 注意 UIKit 框架中的颜色不能直接设置给 CGColorRef
self.demoView.layer.shadowColor = [UIColor yellowColor].CGColor;
// 设置"阴影"的偏移
self.demoView.layer.shadowOffset = CGSizeMake(5, 5);
// 设置"阴影"的透明度(layer 的 opacity 相当于 view 的 alpha)
self.demoView.layer.shadowOpacity = 1.0;
// 设置"阴影"半径
self.demoView.layer.shadowRadius = 10;
// 设置"圆角"效果
self.demoView.layer.cornerRadius = 20;
// 设置"边框"效果
self.demoView.layer.borderColor = [UIColor whiteColor].CGColor;
self.demoView.layer.borderWidth = 2;
- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置控制器 view 的背景颜色, 更好的观察
    self.view.backgroundColor = [UIColor grayColor];
    [self demoImageView];
     // 设置"阴影"
    //    self.demoImageView.layer.shadowColor = [UIColor yellowColor].CGColor;
    //    self.demoImageView.layer.shadowRadius = 70;
    //    self.demoImageView.layer.shadowOffset = CGSizeMake(0, 0);
    //    self.demoImageView.layer.shadowOpacity = 1.0;
    self.demoImageView.layer.cornerRadius = 50;
    self.demoImageView.layer.borderWidth = 3;
    self.demoImageView.layer.borderColor = [UIColor blueColor].CGColor;
    // 注意: "阴影"效果" 和 "裁剪"不能同时应用
    // CALayer 的 masksToBounds 类似于 UIView 的 clipsToBounds
    self.demoImageView.layer.masksToBounds = YES;
    // 保存图片
 UIGraphicsBeginImageContextWithOptions(self.demoImageView.bounds.size, NO, 0.0);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [self.demoImageView.layer renderInContext:ctx];
    UIImage *imgIcon = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(imgIcon, nil, nil, nil);
}
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
     CALayer *layer = [[CALayer alloc] init];
     // ------------------- 设置位置大小 ---------------------
     // 方式一: 直接设置 frame
     // layer.frame = CGRectMake(50, 50, 200, 200);
     // 方式二:
     // 先设置大小
     layer.bounds = CGRectMake(0, 0, 100, 100);
     // 再设置位置(默认情况下 position 指的是 center。)
     layer.position = CGPointMake(150, 150);
     // ------------------- 设置位置大小 ---------------------
     layer.backgroundColor = [UIColor redColor].CGColor;
     layer.opacity = 0.7;
     [self.view.layer addSublayer:layer];
 }

2> 在控制器的 view 中添加一个能显示图片的 layer

参考:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CALayer *layer = [[CALayer alloc] init];
// ------------------- 设置位置大小 ---------------------
// 方式一: 直接设置 frame
// layer.frame = CGRectMake(50, 50, 200, 200);
// 方式二:
// 先设置大小
layer.bounds = CGRectMake(0, 0, 100, 100);
// 再设置位置(默认情况下 position 指的是 center。)
layer.position = CGPointMake(150, 150);
// ------------------- 设置位置大小 ---------------------
layer.backgroundColor = [UIColor redColor].CGColor;
layer.opacity = 1.0;
UIImage *imgBg = [UIImage imageNamed:@"header_home"];
// UIKit 中使用的是 Foundation 框架, 而 Foundation 框架又使用的是 Core Foundation 框架
// Core Foundation 框架都是 C 语言的, 一般凡是 Core Xxxx 的框架都是 C 语言的。
// __bridge 类型 表达式, 的作用一般就是把 Core Foundation 中的数据类型转换成 Foundation 中的类型, 桥接的时候也会设置到一些所有权的转换等。
layer.contents = (__bridge id)(imgBg.CGImage);
[self.view.layer addSublayer:layer];
}

3> CALayer的"可动画属性"

// 通过position 修改 位置

@interface ViewController ()
@property (nonatomic, weak) CALayer *myLayer;
@end
@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CALayer *layer = [[CALayer alloc] init];
self.myLayer = layer;
// ------------------- 设置位置大小 ---------------------
// 方式一: 直接设置 frame
// layer.frame = CGRectMake(50, 50, 200, 200);
// 方式二:
// 先设置大小
layer.bounds = CGRectMake(0, 0, 100, 100);
// 再设置位置(默认情况下 position 指的是 center。)
layer.position = CGPointMake(150, 150);
// ------------------- 设置位置大小 ---------------------
layer.backgroundColor = [UIColor redColor].CGColor;
layer.opacity = 1.0;
UIImage *imgBg = [UIImage imageNamed:@"header_home"];
// UIKit 中使用的是 Foundation 框架, 而 Foundation 框架又使用的是 Core Foundation 框架
// Core Foundation 框架都是 C 语言的, 一般凡是 Core Xxxx 的框架都是 C 语言的。
// __bridge 类型 表达式, 的作用一般就是把 Core Foundation 中的数据类型转换成 Foundation 中的类型, 桥接的时候也会设置到一些所有权的转换等。
layer.contents = (__bridge id)(imgBg.CGImage);
[self.view.layer addSublayer:layer];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = touches.anyObject;
CGPoint point = [touch locationInView:touch.view];
self.myLayer.position = point;
}
@end

总结: iOS 中的动画都是"属性动画", 只要修改 layer的动画属性, 即可实现动画。联想之前的[UIView animateWithDuration:]动画方法。

// 通过 transform 属性进行形变

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
     UITouch *touch = touches.anyObject;
     CGPoint point = [touch locationInView:touch.view];
     // 设置 layer 的位置(默认 position 表示中心点的位置)
     self.myLayer.position = point;
      // 缩放(生成一个0.6~ 1.0之间的随机数)
     //    CGFloat scale = (arc4random_uniform(5) + 1) / 10.0 + 0.5; //0.5;
     //    self.myLayer.transform = CATransform3DMakeScale(scale, scale, 0);
     // 旋转
     CGFloat rotate = arc4random_uniform(M_PI * 2);
     self.myLayer.transform = CATransform3DMakeRotation(rotate, 0, 5, 0);
 }

2> 旋转

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
     UITouch *touch = touches.anyObject;
     CGPoint point = [touch locationInView:touch.view];
     // 设置 layer 的位置(默认 position 表示中心点的位置)
     self.myLayer.position = point;
     // 缩放(生成一个0.6~ 1.0之间的随机数)
     CGFloat scale = (arc4random_uniform(5) + 1) / 10.0 + 0.5; //0.5;
     self.myLayer.transform = CATransform3DMakeScale(scale, scale, 0);
     // 旋转
     CGFloat rotate = arc4random_uniform(M_PI * 2);
     self.myLayer.transform = CATransform3DMakeRotation(rotate, 0, 0, 10);
 }

// 问题:在 touchesBegan 方法中先后指定了 transform, 这样后指定的 transform 会覆盖前面的 transform, 所以现在的效果是只旋转,不缩放了。
// 解决: 通过 kvc 解决:
参考解决办法:

// 缩放(生成一个0.6~ 1.0之间的随机数)
CGFloat scale = (arc4random_uniform(5) + 1) / 10.0 + 0.5;
//self.myLayer.transform = CATransform3DMakeScale(scale, scale, 0);
[self.myLayer setValue:@(scale) forKeyPath:@"transform.scale"];
// 旋转
CGFloat rotate = arc4random_uniform(M_PI * 2);
//self.myLayer.transform = CATransform3DMakeRotation(rotate, 0, 0, 10);
[self.myLayer setValue:@(rotate) forKeyPath:@"transform.rotation"];
 struct CATransform3D
 {
     CGFloat m11, m12, m13, m14;
     CGFloat m21, m22, m23, m24;
     CGFloat m31, m32, m33, m34;
     CGFloat m41, m42, m43, m44;
 };
 struct CGAffineTransform {
     CGFloat a, b, c, d;
     CGFloat tx, ty;
 };

// 圆角,透明度,边框
参考:

// 圆角
self.myLayer.cornerRadius = 20;
self.myLayer.masksToBounds = YES;
// 透明度
self.myLayer.opacity = 0.5;
// 设置边框
self.myLayer.borderColor = [UIColor redColor].CGColor;
self.myLayer.borderWidth = 5;

Quartz Core框架不需要导入, 已经默认导入了


 可以通过动画事务(CATransaction)关闭默认的隐式动画效果
 [CATransaction begin];
 [CATransaction setDisableActions:YES];
 self.myview.layer.position = CGPointMake(10, 10);
 [CATransaction commit];
 - (void)viewDidLoad {
 [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
 CALayer *layer = [[CALayer alloc] init];
 layer.backgroundColor = [UIColor blueColor].CGColor;
 layer.bounds = CGRectMake(0, 0, 100, 100);
 layer.position = CGPointMake(200, 200);
 [self.view.layer addSublayer:layer];
 self.blueLayer = layer;
 }
 
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 UITouch *touch = touches.anyObject;
 CGPoint point = [touch locationInView:touch.view];
 [CATransaction begin];
 [CATransaction setDisableActions:YES];
 self.blueLayer.position = point;
 [CATransaction commit];
 }

附:


transform的属性列表.png
Snip.png
 // 核心代码
 CADisplayLink *timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(moveSecond)];
 [timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];

 - (void)viewDidLoad {
 [super viewDidLoad];
 // 1. 创建表盘
 UIView *clockView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
 clockView.backgroundColor = [UIColor blueColor];
 clockView.center = CGPointMake(self.view.bounds.size.width * 0.5, self.view.bounds.size.height * 0.5);
 [self.view addSubview:clockView];
 self.clockView = clockView;
 
 // 2. 创建秒针
 UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 50)];
 secondView.backgroundColor = [UIColor redColor];
 secondView.layer.anchorPoint = CGPointMake(0.5, 1);
 secondView.center = clockView.center;
 [self.view addSubview:secondView];
 self.secondView = secondView;
 [self moveSecond];
 
 // 3. 启动一个计时器, 每隔一秒钟计算一下当前秒针的位置, 然后做一次哦旋转操作
 // [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(moveSecond) userInfo:nil repeats:YES];
 
 CADisplayLink *timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(moveSecond)];
 [timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
 }
 
 - (void)moveSecond
 {
 // 1. 计算当前的秒数
 NSDate *nowDate = [NSDate date];
 NSCalendar *calendar = [NSCalendar currentCalendar];
 NSInteger seconds = [calendar component:NSCalendarUnitSecond fromDate:nowDate];
 // 2. 计算每一秒的弧度
 CGFloat rotation = M_PI * 2 / 60;
 // 3. 用每一秒的弧度 * 秒数 , 计算出本次要旋转的弧度
 rotation = seconds * rotation;
 // 4. 旋转秒针
 self.secondView.transform = CGAffineTransformMakeRotation(rotation);
 }
 
 // 每次触摸一次屏幕秒针转一次
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 CGFloat rotation = M_PI * 2 / 60;
 self.secondView.transform = CGAffineTransformRotate(self.secondView.transform, rotation);
 }
 
 @end
  1. 核心动画

2.1 基本动画: 位移
案例: 触摸屏幕, 设置指定的 view 的 layer的 position值
参考:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1. 创建动画对象
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
// 默认动画时间是0.25秒
animation.duration = 2.0;
// 2. 设置动画属性值
animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(200, 30)];
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(240, 500)];

// 3. 将动画添加到对应的layer 中
[self.blueView.layer addAnimation:animation forKey:@"animation1"];
}


- (void)viewDidLoad {
[super viewDidLoad];

UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 100, 100)];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueView];
self.blueView = blueView;
}

• 解决:
解决1:当动画执行完毕以后, 手动设置控件的位置。在动画的代理方法(动画结束的时候设置控件的 center)
//self.blueView.center = CGPointMake(300, 50);
注意: 不指定 fromValue 的情况下, 如果直接在添加完毕动画后, 设置控件的 center = 最终的终点有问题!!!所以不要在添加完动画以后直接设置 center 为最终的终点, 而要放到代理方法中。

解决2:
动画执行完毕后不要删除动画对象
设置 fillMode
// 当动画执行完毕后不要删除动画对象
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
缺点: 无法与用户交互, 因为 frame 就没变

3> 介绍隐式代理
4> 不指定 fromValue 就是从当前位置开始动画
5> 注意:

参考:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1. 创建动画对象
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
// 默认动画时间是0.25秒
animation.duration = 2.0;
// 设置动画代理
animation.delegate = self;

// 当动画执行完毕后不要删除动画对象
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

// 2. 设置动画属性值
//animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(200, 30)];
animation.fromValue = [NSValue valueWithCGPoint:self.blueView.center];
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(240, 500)];

// 3. 将动画添加到对应的layer 中
[self.blueView.layer addAnimation:animation forKey:@"animation1"];

// 动画执行完毕后设置控件的 center
//NSLog(@"★");
//self.blueView.center = CGPointMake(300, 50);
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
NSLog(@"%@----", NSStringFromCGRect(self.blueView.frame));

NSLog(@"========%@", NSStringFromCGRect(self.blueView.layer.frame));

NSLog(@"========%@", NSStringFromCGPoint(self.blueView.layer.position));
//self.blueView.center = CGPointMake(300, 50);
}



//-------------------- 参考-----------------
// 1. 创建动画对象
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
// 默认动画时间是0.25秒
animation.duration = 1.0;
// 设置动画代理
animation.delegate = self;

// 当动画执行完毕后不要删除动画对象
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

// 2. 设置动画属性值
//animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(200, 30)];
// animation.fromValue = [NSValue valueWithCGPoint:self.blueView.center];
//animation.toValue = [NSValue valueWithCGPoint:CGPointMake(240, 500)];
animation.toValue = [NSValue valueWithCGPoint:location];

// 3. 将动画添加到对应的layer 中

// 这样每次会添加一个新的动画
//self.blueView.layer addAnimation:animation forKey:nil] ;
// 注意: 如果下面的 key 指定了一个写死的 key,@"animation100",这样不会每次都添加一个新的动画了。
[self.blueView.layer addAnimation:animation forKey:@"animation100"];
// 动画执行完毕后设置控件的 center
//NSLog(@"★");
//self.blueView.center = CGPointMake(300, 50);

2.2 基本动画: 缩放动画
参考:

// 缩放动画
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 创建动画对象
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
// 设置动画属性
anim.fromValue = @(1.0f);
anim.toValue = @(0.7f);
// 设置重复次数
anim.repeatCount = 10;

// 将动画对象添加到 layer 中
[self.blueView.layer addAnimation:anim forKey:nil];
}

2.3 基本动画: 旋转动画
参考

 // 旋转动画
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 
 CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
 
 anim.duration = 3;
 anim.repeatCount = CGFLOAT_MAX;
 // 不要每次都设置起始度数
 //anim.fromValue = @(0);
 anim.toValue = @(M_PI * 2);
 
 [self.blueView.layer addAnimation:anim forKey:nil];
 }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 判断如果已经有动画对象了, 就不再添加了
if ([self.blueView.layer animationForKey:@"anim1"] != nil) {
return;
}

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

anim.duration = 3;
anim.repeatCount = CGFLOAT_MAX;
// 不要每次都设置起始度数
//anim.fromValue = @(0);
anim.toValue = @(M_PI * 2);

[self.blueView.layer addAnimation:anim forKey:@"anim1"];
}
// 暂停
- (void)applicationWillResignActive:(UIApplication *)application {
ViewController *vc =  (ViewController *)self.window.rootViewController;
[vc pause];
}

// 恢复
- (void)applicationDidBecomeActive:(UIApplication *)application {
ViewController *vc =  (ViewController *)self.window.rootViewController;
[vc resume];
}

2.4 关键帧动画

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.duration = 3;
anim.removedOnCompletion = NO;
CGPoint p1 = CGPointMake(10, 10);
CGPoint p2 = CGPointMake(10, 110);
CGPoint p3 = CGPointMake(110, 110);
CGPoint p4 = CGPointMake(110, 10);
CGPoint p5 = CGPointMake(10, 10);
anim.values = @[[NSValue valueWithCGPoint:p1], [NSValue valueWithCGPoint:p2], [NSValue valueWithCGPoint:p3], [NSValue valueWithCGPoint:p4],[NSValue valueWithCGPoint:p5]];
[self.blueView.layer addAnimation:anim forKey:nil];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.duration = 3;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 150, 150)];
anim.path = path.CGPath;

[self.blueView.layer addAnimation:anim forKey:nil];
}
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 if ([self.blueView.layer animationForKey:@"shake"]) {
 return;
 }
 
 CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
 anim.values = @[@(-M_PI / 36), @(M_PI / 36), @(-M_PI / 36)];
 anim.duration = 0.15;
 anim.repeatCount = CGFLOAT_MAX;
 [self.blueView.layer addAnimation:anim forKey:@"shake"];
 
 }
 // 动画组, 组动画
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
 UITouch *touch = touches.anyObject;
 CGPoint location = [touch locationInView:touch.view];
 CAAnimationGroup *groupAnim = [[CAAnimationGroup alloc] init];
 
 // 位移
 CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"position"];
 anim1.toValue = [NSValue valueWithCGPoint:location];
 
 // 缩放
 CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
 anim2.toValue = @(0.3);
 // 旋转
 CABasicAnimation *anim3 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
 anim3.toValue = @(M_PI * 8);
 // 关键帧动画
 CAKeyframeAnimation *anim4 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
 UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(180, 150, 150, 150)];
 anim4.path = path.CGPath;
 groupAnim.animations = @[anim1, anim2, anim3, anim4];
 groupAnim.duration = 1.0;
 groupAnim.repeatCount = CGFLOAT_MAX;
 
 [self.blueView.layer addAnimation:groupAnim forKey:nil];
 }
- (IBAction)swipeLeft:(UISwipeGestureRecognizer *)sender {

// 创建一个转场动画对象
CATransition *anim = [[CATransition alloc] init];
// 设置过度类型
anim.type = @"cube";

if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
anim.subtype = kCATransitionFromRight;
} else {
anim.subtype = kCATransitionFromLeft;
}
[self.imgViewIcon.layer addAnimation:anim forKey:nil];
}

//-------------------------------------------------------
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imgViewIcon;
@property (nonatomic, assign) int index;
@end

@implementation ViewController

- (IBAction)swipeLeft:(UISwipeGestureRecognizer *)sender {
// 创建一个转场动画对象
CATransition *anim = [[CATransition alloc] init];
// 设置过度类型
anim.type = @"cube";

if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
anim.subtype = kCATransitionFromRight;
self.index--;
} else {
anim.subtype = kCATransitionFromLeft;
self.index++;
}
if (self.index < 0) {
self.index = 4;
}
if (self.index > 4) {
self.index = 0;
}
NSString *imgName = [NSString stringWithFormat:@"%d", (self.index + 1)];
self.imgViewIcon.image = [UIImage imageNamed:imgName];
[self.imgViewIcon.layer addAnimation:anim forKey:nil];
}

//-------------- 通过 uiview 实现转场动画-----------
- (IBAction)swipeLeft:(UISwipeGestureRecognizer *)sender {
UIViewAnimationOptions option;
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
option = UIViewAnimationOptionTransitionCurlUp;
self.index--;
} else {
option = UIViewAnimationOptionTransitionCurlDown;
self.index++;
}
if (self.index < 0) {
self.index = 4;
}
if (self.index > 4) {
self.index = 0;
}
NSString *imgName = [NSString stringWithFormat:@"%d", (self.index + 1)];
self.imgViewIcon.image = [UIImage imageNamed:imgName];
[UIView transitionWithView:self.view duration:1.0 options:option animations:^{
// 在转场动画的过程中还可以执行其他的动画
} completion:^(BOOL finished) {
// 动画执行完毕后要做的事情
}];
}
上一篇 下一篇

猜你喜欢

热点阅读