2012-09-24 161 views
-1

我正在創建一個應用程序,允許用戶在線路或路徑上方觸摸。我想做一些事情,像用戶應該能夠利用該行的20個像素。我搜索了很多,但什麼都沒找到。iPhone - 觸摸區域檢測

+0

請更具體..... – IronManGill

回答

1

以下是我的一個程序中的一段代碼:在這裏我做了類似的事情。無論用戶在屏幕上點按哪個位置都會顯示圖像。我已將屏幕限制在某些區域,只有在龍頭將被註冊的地方。希望這可以幫助你:!

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


    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 
    image=[UIImage imageNamed:@"anyImage.gif"]; 
    newView = [[UIImageView alloc]initWithImage:image]; 
    if (location.y<117 || location.y>354) 
    { 
     newView.frame = CGRectMake (location.x, location.y,87,70); 
     newView.center=location; 
     [self addSubview:newView]; 

    } 

    if (location.y<90) 
    { 
     if(location.y>85) 
     { 
      if (location.x>133 || location.x<183) 
      { 

       [self shakeA]; //A method shakeA is called 

      } 
     } 
    } 
    else if (location.y<360) 
    { 
     if (location.y>354) 
     { 
      if (location.x>133 || location.x<183) 
      {  
       [self shakeB]; // Method shakeB called 

      } 
     } 
    } 
} 
+1

您的回答有幫助。但我想檢測圖像的觸摸。例如,如果(point.x> = myimage的位置){//做些事情}。 – Smith

+1

只需找出myImage的座標,然後使用類似的邏輯來註冊圖像周圍的抽頭。 –