///设置动画的节奏。。。。EaseIn 就是刚进入的时候慢。。。
animation.timingFunctino = [CAMediaTimingFunction functionWithName:KCAMediaTimingFunctionEaseInaseOut];
// 设置锚点和位置,,,默认锚点为0.0、右下角为1,1
btn.layer.anchorPoint = CGPointMake(0.5, 1);
btn.layer.position = CGPointMake(self.centerWheel.frame.size.width * 0.5, self.centerWheel.frame.size.height * 0.5);
if (self.link) return;
// 1秒内刷新60次——刷新快的时候比NSTimer好。
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
self.link = link;
- (void)update
{
self.centerWheel.transform = CGAffineTransformRotate(self.centerWheel.transform, M_PI / 500);
}
/**
* 开始选号
*/
- (IBAction)startChoose {
[selfstopRotating];
CABasicAnimation *anim = [CABasicAnimationanimation];
anim.keyPath = @"transform.rotation";
anim.toValue = @(2 * M_PI * 3);
anim.duration = 1.5;
// 开头和结尾比较慢,中间快
anim.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.delegate = self;
[self.centerWheel.layeraddAnimation:anim forKey:nil];
self.userInteractionEnabled = NO;
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
self.userInteractionEnabled = YES;
///两秒后执行里面的方法。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[selfstartRotating];
});
}