先看效果:
什么?太模糊!
来一张高清无码
背景旋转
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
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; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
[ 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];///没有的话是均匀的动画。
return animation;
}
轨迹动画
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