2011-02-07 2 views

Répondre

0

Voici le code qui fait la rotation.

 
-(void)LongPress:(UILongPressGestureRecognizer *)gesture { 

    CGPoint p = [gesture locationInView:self.view]; 

    CGPoint zero; 
    zero.x = self.view.bounds.size.width/2.0; 
    zero.y = self.view.bounds.size.height/2.0; 

    CGPoint newPoint; 

    newPoint.x = p.x - zero.x; 
    newPoint.y = zero.y - p.y; 
    CGFloat angle; 
    angle = atan2(newPoint.x, newPoint.y); 
    self.myButton.transform = CGAffineTransformRotate(CGAffineTransformIdentity, angle); 

} 
0

En détail, vous pouvez personnaliser un RotationVue, puis:

1: Dans la méthode délégué de "touchesBegan", se initialPoint du doigt et initialAngle.

2: Au cours de "touchesMoved", obtenir le newPoint du doigt:

CGPoint newPoint = [[touches anyObject] locationInView:self]; 
    [self pushTouchPoint:thePoint date:[NSDate date]]; 
    double angleDif = [self angleForPoint:newPoint] - [self angleForPoint:initialPoint]; 
    self.angle = initialAngle + angleDif; 
    [[imageView layer] setTransform:CATransform3DMakeRotation(angle, 0, 0, 1)]; 

3: Enfin, dans "touchesEnded" vous pouvez calculer finale AngularVelocity.

Si quelque chose est confondu, pour plus de détails, vous pouvez réécrire.

Questions connexes