我需要在用戶進行UIRotationGesture時旋轉方塊。CALayer轉換
我有所有設置的手勢。問題在於,每當用戶移動手指時,方塊就會返回到起始位置,然後移動到新的位置。而不是從以前的位置移動到新的位置。
即如果正方形的旋轉90度,並且用戶繼續旋轉到100平方將回到0度和動畫爲100
基本上我希望廣場鏡像用戶時他們執行旋轉手勢。
- (void)respondToGesture:(UIRotationGestureRecognizer *)rec{
NSLog(@"Rotation: %f", rec.rotation);
[self rotateWithRadian:rec.rotation];
if (rec.state == UIGestureRecognizerStateEnded) {
NSLog(@"gesture ended");
}
}
- (void)rotateWithRadian:(float)radian{
CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spin.removedOnCompletion = NO;
spin.fillMode = kCAFillModeForwards;
[spin setByValue:[NSNumber numberWithFloat:radian]];
[spin setDuration:1.0];
[squarelayer addAnimation:spin forKey:@"spinAnimation"];
現貨作品完美乾杯! – geminiCoder 2012-02-01 12:50:54