先看效果:
QQ20171222-170814-HD.gif
什么?太模糊这嚣!
來(lái)一張高清無(wú)碼
圖片.png
背景旋轉(zhuǎn)
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//默認(rèn)是順時(shí)針效果绞惦,若將fromValue和toValue的值互換,則為逆時(shí)針效果
animation.fromValue = [NSNumber numberWithFloat:0.f];
animation.toValue = [NSNumber numberWithFloat: M_PI *2];
animation.duration = 200;
animation.autoreverses = NO;
animation.fillMode =kCAFillModeForwards;
animation.repeatCount = MAXFLOAT; //如果這里想設(shè)置成一直自旋轉(zhuǎn),可以設(shè)置為MAXFLOAT遏弱,否則設(shè)置具體的數(shù)值則代表執(zhí)行多少次
[ self.bgImaegview.layer addAnimation:animation forKey:nil];
星星的閃爍
-(CABasicAnimation *)opacityForever_Animation:(float)time
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];//必須寫opacity才行。
animation.fromValue = [NSNumber numberWithFloat:1.0f];
animation.toValue = [NSNumber numberWithFloat:0.0f];
animation.autoreverses = YES;
animation.duration = time;
animation.repeatCount = MAXFLOAT;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];///沒(méi)有的話是均勻的動(dòng)畫塞弊。
return animation;
}
軌跡動(dòng)畫
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = CGFLOAT_MAX;
pathAnimation.duration = 30.0;
CGMutablePathRef ovalfromarc = CGPathCreateMutable();
CGAffineTransform t2 = CGAffineTransformConcat(CGAffineTransformConcat( CGAffineTransformMakeTranslation(-origin_x,-origin_y), CGAffineTransformMakeScale(1, radiuscale)), CGAffineTransformMakeTranslation(origin_x, origin_y));
CGPathAddArc(ovalfromarc, &t2, origin_x, origin_y, radiusX,beginAng,endAng, 0);
pathAnimation.path = ovalfromarc;
CGPathRelease(ovalfromarc);
繪制橢圓
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIBezierPath *arc = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20+40, 25, SCREEN_WIDTH-40,SCREEN_WIDTH/2-50)];
[COLOR(147.f, 151.f, 157.f,0.5f) setStroke];
[arc stroke];
CGContextRestoreGState(context);
下面是demo地址
鏈接: https://pan.baidu.com/s/1bp4jHWr 密碼: 5mt6