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

增加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
复制代码

你可能感兴趣的:(iOS视频处理之增加动画挂件和Image边框)