Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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];
}   
like image 754
Mano Avatar asked Jul 04 '13 10:07

Mano


2 Answers

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.

like image 185
Rushi Avatar answered Sep 28 '22 20:09

Rushi


try

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event touchesForView:vTouch] anyObject];
    if(!touch)
        return;

    CGPoint pointNow = [touch locationInView:otherView];
    {
        // code here
    }
}
like image 32
geo Avatar answered Sep 28 '22 20:09

geo