How to make 'touchesBegan' method work for a specific view?

Mano picture Mano · Jul 4, 2013 · Viewed 25.8k times · Source

In my add contact page, i have a view and a scrollview on it and again a view on it. and in that last view i ve textboxes, etc. i have given the 'touchesBegan' method but it is called only for the view at the bottom. how to point that method to another view i.e., the view at the top?

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 [self.AddView endEditing:YES];
}   

Answer

Rushi picture Rushi · Jul 4, 2013

One way this is how you can do :

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch= [touches anyObject];
    if ([touch view] == image1)
    {
        //Action
    }

}

Please Note : As you are using UIScrollView you might not able to get touches method for UIScrollView. In that case you might have to use UIGesture.