2011-07-12 66 views
3

我在UIView中做了這個觸摸動作,即在UI中有 有兩個或三個子視圖v1,v2,v3。我使用下面的代碼將圖像i1,i2,i3放置在相應的視圖中,如果我移動了圖像,圖像將移動到視圖中的那一點。UIScrollview touchesbegan,touchesmoved,touchesended actions

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    if ([touch view] == v1) 
    { 
     CGPoint location = [touch locationInView:v1]; 
     i1.center = location; 
    } 
     else if([touch view] == v2) 
    { 
     CGPoint location = [touch locationInView:v2]; 
     i2.center = location; 
    } 
} 
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 
    if ([touch view] == v1) 
    { 
     CGPoint location = [touch locationInView:v1]; 
     i1.center = location; 
    } 
     else if([touch view] == v2) 
    { 
     CGPoint location = [touch locationInView:v1]; 
     i2.center = location; 
    } 
} 

現在,我必須這樣做28個圖像序列,所以我去了UIScrollView的,但我不能得到那個請我解釋清楚的代碼。非常感謝您的幫助。

回答

2

您需要繼承UIScrollView以獲取UIScrollView的觸摸事件。

+3

如何子類uiscrollview請解釋它請 – NAZIK

+1

通過此鏈接http://iphonedevelopertips.com/user-interface/detect-single-tap-in-uiscrollview.html –

+0

謝謝@Rahul Vyas。 – NAZIK

相關問題