iOS视频处理之增加动画挂件和Image边框

本文介绍如何为PNG格式的图片添加边框,并通过CABasicAnimation实现动画效果。主要内容包括:设置背景Layer来增加边框;使用CABasicAnimation实现旋转动画。

增加Image边框.首先Image必须为png格式.空白的地方要是那种透明的,而不是白色. 只需要修改背景Layer.

UIImage* overlayImage=[UIImage ImageNamed:@"frame.png"];
    CALayer *backgroundLayer = [CALayer layer];
  [backgroundLayer setContents:(id)[overlayImage CGImage]]; //overlayImage为UIImage对象
    backgroundLayer.frame = CGRectMake(0, 0, naturalSize.width, naturalSize.height);
复制代码

增加动画挂件.这里需要使用到CABasicAnimation

首先我们依旧要用到ImageLayer

  UIImage *animationImage = [UIImage imageNamed:@"star.png"];;
  CALayer *overlayLayer = [CALayer layer];
  [overlayLayer setContents:(id)[animationImage CGImage]];
  overlayLayer.frame = CGRectMake(size.width/2-64, size.height/2 + 200, 128, 128);
  [overlayLayer setMasksToBounds:YES];

    CABasicAnimation *animation =
    [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.duration=2.0;
    animation.repeatCount=5;
    animation.autoreverses=YES;
    animation.fromValue=[NSNumber numberWithFloat:0.0];
    animation.toValue=[NSNumber numberWithFloat:(2.0 * M_PI)];
    animation.beginTime = AVCoreAnimationBeginTimeAtZero;
    [overlayLayer addAnimation:animation forKey:@"rotation"];
//然后添加到parentLayer中就好. 动画完成.关于`CABasicAnimation`.请自行寻找教程
复制代码

demo:

https://github.com/sunstrider12/theVideo
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值