Having trouble hiding keyboard using invisible button which sits on top of uiscrollview

Posted by phil on Stack Overflow See other posts from Stack Overflow or by phil
Published on 2011-02-28T23:22:23Z Indexed on 2011/02/28 23:24 UTC
Read the original article Hit count: 244

I have 3 items in play...

1) UIView sits at the base of the hierarchy and contains the UIScrollview. 2) UIScrollview that is presenting a lengthy user form. 3) An invisible button on the UIScrollview that I'm using to provide "hide the keyboard" features.

Notice in the code below that I'm registering to be notified when the keyboard is going to appear and again when it's going to disappear. These are working great.

My problem is seemingly one of "layers". See below where I insert the button into the view atIndex:0. This causes the button to be activated and "stuffed" behind the scrollview so that when you click on it, the scrollview grabs the touch and the button is unaware. There is no way to "reach" the button and suppress the keyboard.

However, if I insert atIndex:1, the button gets super imposed on top of the text entry fields and so any touch at all is acted upon by the button, which immediately suppresses the keyboard and then disappears.

How do I insert the button on top of the UIScrollview but behind the UITextfields that sit there?


other logistics: I have a -(void) hidekeyboard function that I have setup with the UIButtion as an IBAction(). And I have the UIButton connected to "files owner" via a ctrl-drag/drop. (Do I need both of those conventions?)

This code in ViewDidLoad()...

[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:nil usingBlock:^(NSNotification *notification){

[self.view insertSubview:self.keyboardDismissalButton atIndex:0];

}];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c