touchesBegan withEvent is not responding in uiscrollview

2.2k Views Asked by At

What I had done in my xib file is that, Initially I had an uiImageView and over that I had an UIScrollView on which i had put so many other controls. Earlier I was not having scroll view so my touchesBegan event was working properly but now after putting UIScrollView its not responding. I am new in iOS so please tell me what to do?? What I want to do is to hide my keyboard which appears for my UITextView, whenever I touch anywhere on screen. So please help me out... the code of my touchesBegan method is:

(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([self.txtLoginId isFirstResponder] && [touch view] != self.txtLoginId)
{
    [self.txtLoginId resignFirstResponder];
}
if ([self.txtPassword isFirstResponder] && [touch view] != self.txtPassword)
{
    [self.txtPassword resignFirstResponder];
}
    [super touchesBegan:touches withEvent:event];
}
1

There are 1 best solutions below

0
On

Probably, your scrollView has its property userInteractionEnabled set to YES. In this case, the scrollView receives the touches, and they will not be forwarded to your method touchesBegan:withEvent:.
Simply try to set this property to NO. This can be done in storyboard in the view section of the scrollView, or programmatically.