2012-10-29 27 views
0

我已經做了編碼,檢查圖像是否越過特定區域或沒有,如何停止移動目標c中的圖像?

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

CGPoint loc=[touch locationInView:self.view]; 

if (touch.view==img2Obj) { 
    NSLog(@"image2"); 
    img2Obj.center=loc; 

    currentx1=img2Obj.frame.origin.x; 
    currenty1=img2Obj.frame.origin.y; 
    //NSLog(@"top left corner x and y is %.1f and %.1f",img2Obj.frame.origin.x,img2Obj.frame.origin.y); 
    [self isImg1InPos]; 

}} 
-(void)isImg1InPos { 

int dx,dy; 

dx=currentx1-x1; 
dy=currenty1-y1; 
if (abs(dx)<5 && abs(dx)<5) { 
    NSLog(@"Image must stop moving after this!!!"); 
    [img2Obj setUserInteractionEnabled:FALSE]; 
} 
//NSLog(@"unsigned int is %d",abs(dx)); 

} 

我想要的圖像時停止傳遞狀態時移動。

[img2Obj setUserInteractionEnabled:FALSE]; 

但它不工作,誰能告訴我怎麼解決這個問題

很多感謝

+0

條件是否滿足?即,NSLog是否打印該語句? – Ilanchezhian

+0

@Aadhira雅條件滿意,但圖像仍在移動 – Swetha

回答

1

只要保持一個獨立的BOOL值左右,例如所謂的movingEnabled,並根據此標記的值提前退出touchesMoved例程(即在調整圖像位置之前)。

+0

好主意。 Thankzzzz – Swetha