2011-03-18 123 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