Search code examples
xcodexcode4uiscrollviewuitextfield

Hide keyboard on backgroundtap with view which has fullscreen scrollview


I have a UIControl type screen which has a fullscreen UIScrollView and UITextFields on that scrollview. I want to apply hiding keyboard on backgroundtap.

I declared backgroundTap method in header file and implemented it as follows :

- (IBAction)backgroundTap:(id)sender {

    NSLog(@"backgroundtap");

    for(UIView *v in self.scroll.subviews){
        if ([v isKindOfClass:[UITextField class]]) {
            [v resignFirstResponder];
        }
    }
}

I bind this method to UIControl Touch Up Inside action (by dragging and dropping from files owner) but because there is a UIScrollView on top of my UIControl it does not work so when I touch up inside screen indeed I touch my scrollview not my UIControl.

How can I make this keyboard disappear by making UIControl get this touch up inside interaction?

Any help will be appreciated.Thank you.


Solution

  • Putting UIView on top of UIScrollView would be a solution I though recently but using UIScrollView with backgroundtap is not recommended as I see.