2011-02-07 76 views

回答

0

这是使旋转的代码。

 
-(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

详细,你可以自定义一个rotateView,则:

1:在 “touchesBegan” 委托方法,让手指和initialAngleinitialPoint

2:在 “touchesMoved”,让手指的newPoint

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:最后,在 “touchesEnded” 就可以计算出最终AngularVelocity

如果有什么困惑,更详细的信息,你可以回信。