2011-11-10 49 views
0

のシングルフィンガーの回転と平行移動私が移動したい場合は現在、私はこのLink翻訳作業を実行する方法を、私は回転を行った後、疑問に思って画像とその作業fine.Butにシングル指の回転を実行するために、次のい画面の1つの位置から他の位置への画像。のiOS:画像

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // We can look at any touch object since we know we 
    // have only 1. If there were more than 1 then 
    // touchesBegan:withEvent: would have failed the recognizer. 
    UITouch *touch = [touches anyObject]; 

    // A tap can have slight movement, but we're not interested 
    // in a tap. We want more movement. So if a tap is detected 
    // fail the recognizer. 
    if ([self state] == UIGestureRecognizerStatePossible) { 
     [self setState:UIGestureRecognizerStateBegan]; 
    } else { 
     [self setState:UIGestureRecognizerStateChanged]; 
    } 

    // To rotate with one finger, we simulate a second finger. 
    // The second figure is on the opposite side of the virtual 
    // circle that represents the rotation gesture. 

    UIView *view = [self view]; 
    CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds])); 
    CGPoint currentTouchPoint = [touch locationInView:view]; 
    CGPoint previousTouchPoint = [touch previousLocationInView:view]; 

    // use the movement of the touch to decide 
    // how much to rotate the carousel 
    CGPoint line2Start = currentTouchPoint; 
    CGPoint line1Start = previousTouchPoint; 
    CGPoint line2End = CGPointMake(center.x + (center.x - line2Start.x), center.y + (center.y - line2Start.y)); 
    CGPoint line1End = CGPointMake(center.x + (center.x - line1Start.x), center.y + (center.y - line1Start.y)); 

    ////// 
    // Calculate the angle in radians. 
    // (From: http://iphonedevelopment.blogspot.com/2009/12/better-two-finger-rotate-gesture.html) 
    CGFloat a = line1End.x - line1Start.x; 
    CGFloat b = line1End.y - line1Start.y; 
    CGFloat c = line2End.x - line2Start.x; 
    CGFloat d = line2End.y - line2Start.y; 

    CGFloat line1Slope = (line1End.y - line1Start.y)/(line1End.x - line1Start.x); 
    CGFloat line2Slope = (line2End.y - line2Start.y)/(line2End.x - line2Start.x); 

    CGFloat degs = acosf(((a*c) + (b*d))/((sqrt(a*a + b*b)) * (sqrt(c*c + d*d)))); 

    CGFloat angleInRadians = (line2Slope > line1Slope) ? degs : -degs; 
    ////// 

    [self setRotation:angleInRadians]; 
} 

答えて

1

私は私の答えはあなたを助けることを確認していないが、私はあなたが、同時に「ワンタッチ」の回転と「ワンタッチ」の翻訳を行うことができないことを恐れています。実際、あなたのコードは、ディスプレイに触れる第2の指の存在を「シミュレート」することによって、回転に関しては常にワンタッチであると解釈します。あなたはその回転に1と翻訳と他を関連付けるために2つの単一指のジェスチャーをしようとして区別されて何ができるか

。たとえば、翻訳のジェスチャーは「長時間触れる」ことができます(タッチしてしばらく触れ続けてからオブジェクトを移動します)。

これはとにかく、お役に立てば幸いです...

+0

しかし、私が現在使用している画像は、私はそれがproperly.So起きていない二重の指の回転を行う場合は、プロジェクトのrequirement.Onをあるサイズ30 * 30である私することができます、任意の提案や任意のポインタ? – raaz

+0

私が出てくる唯一のことは、私が言ったことです:あなたは(例えば、0.5秒)を押してからイメージをドラッグします。またはスワイプして回転させます。かなり安定していると思われ、30x30画像でうまくいくはずです... – sergio

+0

長押しの場合、UILongPressGestureRecognizerを意味するか、UITouchイベントメソッドで実装する必要があります。 – raaz