動畫怪異的行爲我想作一個圓形滑塊,可拖動和動畫。到目前爲止,我已經設法構建滑塊,並使用拖動手柄來移動它並進行動畫處理。有時,動畫出錯(錯誤的方向或最短的方向。我已經子類化一個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