1让view转动:
CABasicAnimation* rotate = [CABasicAnimation animationWithKeyPath: @"transform.rotation.z"];
rotate.removedOnCompletion = FALSE;
rotate.fillMode = kCAFillModeForwards;
//Do a series of 5 quarter turns for a total of a 1.25 turns
//(2PI is a full turn, so pi/2 is a quarter turn)
[rotate setToValue: [NSNumber numberWithFloat: M_PI / 2]];
rotate.repeatCount = 11;
rotate.duration = 0.25;
// rotate.beginTime = start;
rotate.cumulative = TRUE;
rotate.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[_circleView.layer addAnimation:rotate forKey:@"rotateAnimation"];
------CircleView的drawRect
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGFloat startAngle = -M_PI/3;
CGFloat step = 11*M_PI/6 * self.progress;
CGContextAddArc(context, self.bounds.size.width/2, self.bounds.size.height/2, self.bounds.size.width/2-3, startAngle, startAngle+step, 0);
CGContextStrokePath(context);
}
1设置进度:
_circleView.progress = (moveY-15) / (65-15);
[_circleView setNeedsDisplay];
1去掉动画
double delayInSeconds = 0.2;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[_circleView.layer removeAllAnimations];
});
1
1
1
1