Showing posts with label keyboard. Show all posts
Showing posts with label keyboard. Show all posts

Thursday, October 7, 2010

How to Get Rid of Keyboard with a Tap on Background part2

There was a nice way to remove keyboard by using UITextView, but that has stopped working with iOS4. At least I got such a defect report for beta application. This time I will remove keyboard using UIButton, let's see how long that will work:
- (IBAction)removeKeyboard
{
    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];
}
Open your view in Interface Builder, create new custom full screen UIButton to cover everything, select UITextFields and UIButtons (etc.) one by one and "Send to Front" via Layout menu. Connect UIButton "Touch Up Inside" to your callback and that's it.

Nice, easy, simple, fast - what more can you ask for!

Monday, April 26, 2010

How to Get Rid of Keyboard with a Tap on Background

There is a screen with a couple of UITextFields and UIButtons. When user taps on UITextField, keyboard popups. Very nice of iPhone SDK to provide such a feature! Each UITextField and UIButton is a clickable object with easy callbacks.

But how do you get rid of keyboard?

Should you have a special "Please hide keyboard" button or tap into accelerometer to notice when user gets desperate enough to start shaking the device? There's an easier way...

Add a full-screen empty non-editable UITextView over the whole screen. Select each clickable object e.g. UITextField, UIButton or other UITextViews and use Interface Builder menu item Layout - Send to Front to place them on top of your full-screen UITextField.

When user clicks on anywhere except your clickable objects, keyboard disappears. What a relief!

Please note that, if you leave any non-clickable objects e.g. UILabel on top of your full-screen UITextView, clicking on those spots will not hide keyboard.

Wednesday, January 27, 2010

How to Scroll TextField visible Under Keyboard

Very thorough keyboard handling tutorial "iPhone Programming - Editing TextFields without Obscuring Them" by Steve at act_as_geek blog. Lots of pictures, very patiently walking through how to setup things in Interface Builder!

Wonder how it behaves when you have UITableView somewhere.

Currently I use UIControl as root which contains UINavigationBar, UITableView, UIView and UIButton. When keyboard appears, I got to scroll... well, everything visible. Basically I do what is done in that tutorial, but without UIScrollView. Resize one table and one view. Messy.

Time to refactor. Will try how that sample works.