Hide a custom iPhone control when another portion of the screen is tapped - iphone

My problem is thus: I've created a custom view, a numeric keypad, that I display when a button is pressed. When anywhere else on the screen is tapped, I want to hide the keypad.
I solved the problem by overriding touchesBegan:withEvent. Then a hit test tells me if the numeric keypad was pressed. As long as the keypad wasn't pressed, I hide it (by setting its hidden property to YES).
It works, but I don't like it. Its not very clean. My other option is to have a view controller for the numeric keypad and display it as a modal view controller. The keypad view would have a transparent background. I don't like this method either.
Any ideas?

A simple solution would be to have an invisible UIButton that you add to the view when the keypad comes up and remove along with the keypad when it is tapped.
Of course, the tap you get on the UIButton will prevent you from using that tap for anything else, so your interface wouldn't work while the keypad is there.

Related

How to keep button functionality when adding other views on top of said button in a subclass?

I have a button in my app, but I have create a UIButton subclass that adds another view and a few labels on top of it. The problem is that now in my app the button does not respond to taps. How would I go about fixing this?
I was able to fix this problem by setting the view that was covering my button with the property
userInteractionEnabled = true
That allowed for the text to go through my view back to my button

Content of UIPopoverController slides out of view when Keyboard is dispatched

I have an iPad app who's login screen looks like this (top of image clipped because of sensitive info):
When the user taps "Log In" button I load a UIPopoverController with some buttons:
When the user taps "Email" button, I release the first popover and create another one with two text fields:
Looking good so far, but when the user selects the text field in order to enter text, both of the UITextField controls slide off of the top of the PopoverController, like this:
I am using storyboards/segues for these popover controllers, with a little hand coded stuff to handle device rotations. I am using Autolayout and both of the UITextFields are pinned to the SuperView Top and Leading edge. That is all.
If I move the buttons up more towards the top of the screen (out of the way of the keyboard), this behavior is still present.
What is triggering this and where can I override its behavior?
Did you set the ContentSizeForViewInPopover for the view controller in -viewDidLoad showing textfields?
[self setContentSizeForViewInPopover:CGSizeMake(200, 200)];

iPhone Swipe UIKeyboard to Switch Views

I want to achieve something like this with my application and its keyboard.
http://www.youtube.com/watch?v=ajs1p5NCNw4 from 1:32 - 1:38.
How can you hide your keyboard by swiping it horizontally and show another view on its place? Is it possible with default keyboard or should I create my own view with few buttons which I'll need and then add the swiping? (I know how to do this, but I'm not sure if apple wouldn't deny the app in app store because I implement my own keyboard or something like that)
Those are custom views. It might be a scroll view with paging enabled and two subviews (the numerical keypad is one subview and items view is the other subview).
The app might be using the custom view in place of the system keyboard, by setting the inputView property of a text field for example. Or it might just be displaying the custom view as a subview of its top-level view.

Remove UISearchBar on tableView click

I have a UISearchBar which is subviewed by another view when a button is pressed. When it loads, it looks like the following (minus the red scribbles):
I would like to have the UISearchBar view be removed from the parent view controller when the tableView (the area with red scribbles) is clicked and is empty (no search has been made yet). I'm having a difficult time figuring out the best way to do this.
I have tried to put a transparent button in that section and add it as a subview to the search bar. However the button is underneath the tabl view area, so when the table view is clicked, the search bar loses focus and the uibutton is only then accessible.
Does anyone know how I can remove the search bar from the parent view controller when the empty table view below it is clicked?
Thanks.
To bring the transparent button up and make it catch all touched first, use [button.parentView bringSubViewToFront:button].
Another approach could be to catch the search bar losing focus (since you say you see that happening), by putting
– (void)searchBarTextDidEndEditing:(UISearchBar*)searchBar
in the search bar delegate, and handling it from there.

UITextFieldDelegate != IBAction backgroundTap

The scope of this question is IPhone 3.1 sdk (app running in simulator still)
I have a table view that has a cell with a UITextField in that cell. The table view is grouped, and has one section with just a couple fields. Im NOT using IB so backgroundTap is out of the question (as far as i can tell at least). When i click the text field, keyboard shows. Hiding it is still troublesome. Ive pulled the UITextFieldDelegate into the mix to hide the keyboard but the textFieldShouldEndEditing method doesnt seem to fire when the background is tapped (when i mean background, im tapping outside of the grouped table view section). First off, should it?
textFieldShouldReturn fires with no problem and i can resign at this point but shouldnt i be able to resign if focus shifts away from that control?
Any help is much appreciated
-me
Generally you'll only stop editing a field when you:
hit the "Done" or action button on the keyboard
begin editing another field
exit the view
have another button on screen that removes focus
From any of these, you can call -[textField resignFirstResponder] to dismiss the keyboard and call your -textFieldShouldEndEditing: method. There's no reason that just tapping on a non-active part of the screen should dismiss the keyboard.