2013-04-01 49 views
1

我正在做視圖調整大小,移動和旋轉的單點​​觸摸。確定觸摸移動的方向

我試圖找到觸摸移動方向一樣,

IF觸摸移動方向爲水平或垂直,然後移動視圖。 如果觸摸移動的方向是對角線,然後調整大小。 如果觸摸像旋轉手勢一樣移動,則旋轉視圖。

我能夠識別水平或垂直方向。

請建議我如何識別對角線和旋轉。

回答

1

我想旋轉,你可以簡單地使用這個mehod -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

對於對角線,您可以比較兩個點的座標。 對於對角線,您也可以從post處獲得幫助。

+0

謝謝@Hinata我會試試這個。 – San007

1

在觸摸移動功能,可以識別手指移動這樣的方向。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [super touchesMoved:touches withEvent:event]; 
    UITouch *touch = [touches anyObject]; 
    CGPoint current=[touch locationInView:self]; 
    CGPoint last=[touch previousLocationInView:self]; 

    if(current.x>last.x){ 
     NSLog(@">>>>rigth"); 
    }else{ 
    NSLog(@">>>>left"); 
    } 

    if(current.y>last.y){ 
    NSLog(@">>>>up"); 
    }else{ 
    NSLog(@">>>>down"); 
    } 
}