动画怪异的行为我想作一个圆形滑块,可拖动和动画。到目前为止,我已经设法构建滑块,并使用拖动手柄来移动它并进行动画处理。有时,动画出错(错误的方向或最短的方向。我已经子类化一个UIView(将是一个UIControl很快,只是想立刻先拿到动画)加入了PanGestureRecognizer和若干层的图纸。圆形滑块,同时与CA
?那么,如何解决这个怪异的行为我已经有人可以帮助我在这里,我要感谢:)
这里的样本项目 - >http://cl.ly/2l0O3b1I3U0X
非常感谢!
编辑:
这里的绘图代码:
CALayer *aLayer = [CALayer layer];
aLayer.bounds = CGRectMake(0, 0, 170, 170);
aLayer.position = self.center;
aLayer.transform = CATransform3DMakeRotation(M_PI_4, 0, 0, 1);
self.handleHostLayer = [CALayer layer];
self.handleHostLayer.bounds = CGRectMake(0, 0, 170, 170);
self.handleHostLayer.position = CGPointMake(CGRectGetMaxX(aLayer.bounds) - 170/2.0, CGRectGetMaxY(aLayer.bounds) - 170/2.0);
[aLayer addSublayer:self.handleHostLayer];
[self.layer addSublayer:aLayer];
self.handle = [CALayer layer];
self.handle.bounds = CGRectMake(0, 0, 50, 50);
self.handle.cornerRadius = 25;
self.handle.backgroundColor = [UIColor whiteColor].CGColor;
self.handle.masksToBounds = NO;
self.handle.shadowOffset = CGSizeMake(3.0, 0.0);
self.handle.shadowRadius = 0;
self.handle.shadowOpacity = .15;
self.handle.shadowColor = [UIColor blackColor].CGColor;
[self.handleHostLayer addSublayer:self.self.handle];
这里的动画代码:
CGFloat handleTarget = ToRad(DEG);
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotationAnimation.fromValue = @([[self.handleHostLayer valueForKeyPath:@"transform.rotation"] floatValue]);
rotationAnimation.toValue = @(handleTarget);
rotationAnimation.duration = .5;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.cumulative = YES;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.handleHostLayer addAnimation:rotationAnimation forKey:@"transform.rotation"];
动画代码似乎是问题。你只能发布动画和可能的图纸代码。我不想通过项目来找到它。 –
非常感谢您的帮助!我发布了上面的绘图代码(绘图在drawRect中完成:) – reiserD