2011-03-18 120 views
1

你好我想旋轉單手指觸摸UIView,它仍然旋轉,直到手指在iPhone的屏幕上移動,它停止旋轉,當我停止手指移動或從屏幕上移除它。UIView旋轉

在此先感謝。

回答

8

嘗試類似的代碼

 
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    CGAffineTransform rr=CGAffineTransformMakeRotation(5); 
    yourView.transform=CGAffineTransformConcat(yourView.transform, rr); 
    [UIView commitAnimations]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self touchesBegan:touches withEvent:event]; 
} 
+0

感謝名單.......求救.... – JKMania 2011-03-18 09:35:19

+0

並感謝投票太.... – JKMania 2011-03-18 09:56:20

6

Pradeepa的代碼是好的,但是,動畫系統即將棄用(如果沒有的話)。嘗試這樣的事情,而不是:

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue]; 
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue]; 
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5]; 
rotation.duration = 0.2; 
[yourView.layer addAnimation:rotation forKey:@"rotating"]; 

我把Pradeepa的數字,使他們相媲美,但我認爲,蘋果更喜歡你使用這個或基於塊的動畫,而不是舊系統。

+0

感謝名單的人.....你真的救了我的時間.. ... thanx很多 – JKMania 2011-03-18 09:36:06

+0

謝謝,時間細細品味。 – user268743 2012-05-02 09:05:43