增加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
複製程式碼