我有一張圖片可以使用旋轉手勢進行旋轉,但是我想要根據旋轉速度繼續旋轉圖像。旋轉手勢結束後繼續旋轉圖像
它在我鬆開手指後旋轉,但當它停止時它不會保持在旋轉的角度。它將手指放開後的旋轉角度設置爲最後一個角度。
- (void)rotateCoaster:(UIRotationGestureRecognizer *)recognizer {
if(recognizer.numberOfTouches >= 2) {
twoTouchesDetected = YES;
}
else {
twoTouchesDetected = NO;
}
if(recognizer.state == UIGestureRecognizerStateBegan ||
recognizer.state == UIGestureRecognizerStateChanged)
{
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform,
recognizer.rotation);
_player.rotationVelocity = recognizer.velocity;
_player.rotation = recognizer.rotation;
[recognizer setRotation:0];
}
if(!twoTouchesDetected) {
[self rotationCalculations:nil];
rotating = YES;
}
if(recognizer.state == UIGestureRecognizerStateEnded ||
recognizer.state == UIGestureRecognizerStateCancelled) {
[self dropDownCoaster];
}
_player.rotationVelocity = recognizer.velocity;
}
- (void)rotationCalculations:(NSTimer *) dt {
// dTime += dt.timeInterval;
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration];
CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// animation.fromValue = [NSNumber numberWithFloat:0.0];
// animation.toValue = [NSNumber numberWithFloat:_player.rotationVelocity * M_PI];
animation.fromValue = nil;
animation.toValue = nil;
animation.byValue = [NSNumber numberWithFloat:_player.rotationVelocity * M_PI];
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
animation.delegate = self;
[_coasterImageView.layer addAnimation:animation forKey:@"rotationAnimation"];
[CATransaction commit];
}
「但其停止行爲正常」是非常不精確的。請描述不良行爲以及您期望/希望做的事情。 – NJones 2012-03-11 15:58:32
@NJones我有更新我的文章。對不起,我讀過它,它根本沒有幫助。 – Bassem 2012-03-15 11:46:57