2011-02-07 69 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

如果有什麼困惑,更詳細的信息,你可以回信。