hidden view blocking (and not responding to) gestureRecognizer - swift

I'm trying to dismiss a UITextField using a UITapGestureRecognizer connected to the background image of the view.
#IBAction func dismissKeyboard(sender: UITapGestureRecognizer)
{self.view.endEditing(true)}
When tapping in most places on the background it dismisses just fine, but the problem is, I have a hidden UILabel (which displays a small red "item already added!" on the side if the text in the box matches a previous instance) that seems to get in the way of tapping part of the UIImageView. Adding the Label to the "Referencing Outlet Collections" doesn't help either, because the Label is hidden. I've tested when the label is unhidden and it works fine... Understandably when hidden, the Label doesn't respond to taps, but why does it block the taps of the image beneath it? Any way to make the Label "tapically" hidden as well.
I could make alpha = 0 instead of using hidden, but the method I'm currently using is much more efficient and I can't imagine changing would be the only way to work around this problem.
Any help would be greatly appreciated

Related

How can I highlight the BarButton in navigation bar without tapping it?

Typically, the UIBarButtonItem will be highlighted when we tap it.
However, I intend to show the users that the action is automatically done for them when the view is loaded after 4 sec.
So I want to highlight the Button without tapping it.
How can I achieve that?
For a UIVIew object such as a UIButton, you can either use the following code Glow category on UIView that adds support for making views glow or use this example.
If you are using the first one, you can just call startGlowing and stopGlowing. When you call startGlowing, the view will start to pulse with a soft light, this effect is removed when stopGlowing is called. Check this.
For UIBarButtonItem, you might have to use the solution provided here.

Custom UIBarButtonItem highlight issue

I have a toolbar with 5 buttons.
4 of them are regular bar button items and one of them is a custom one (A 'UIButton' inside a 'UIBarButtonItem').
I noticed that when I click between the regular buttons (not exactly on them), one of them (the closest one) still recieves the click event and is being highlighted (which is what I want).
But the custom bar button item does not show this behaviour.
When I tap between it and one of the regular buttons neither of the 2 receives the touch event. This probably because the UIButton is the one the gets the click event. Is there a way to add a touch event the containing bar button item as well? Or perhaps another way to solve this?
Thanks!
button.userInteractionEnabled = YES; I believe is the answer.
One solution might be that you create image of same as bar button item and assign to UIButton as background image, this will solve your issue.
Hope this helps you....
Solved it!
I added another UIView to the UIBarButtonItem and then I added the UIButton to the UIView.
I added a touch gesture to the UIView (And also kept the original touch event of the UIButton) that expanded the area that you can touch the button which solved the problem.

UISearchBar: how can I stop it resizing when clicked?

I have a UISearchBar (with UISearchDisplayController) as title view of UINavigationBar. There are also two buttons on either side of the searchbar within the navbar.
When clicking on UISearchBar, it becomes wider and covers the button on the right of it.
How can I stop it from becoming wider?
Things tried but didn't work -->
The widened search bar then becomes the original size if the device is rotated.
So, tried calling [searchBar setNeedsLayout] in -searchBarTextDidBeginEditing
All different auto-resizing mask options in IB
Edit: Didn't mention, but this is on iPhone (as we can put searchbar inside toolbar in iPad..)
Actually, taking hint from this answer if the search bar is put in UIView of desired size then this is set as title view of NavBar, it doesn't go wider !
But... Since you can't make cancel button to show/not show as you wish, I realized it's not so useful.
(As seen in this question/answer etc)

How to make the MapView a button (iPhone/iPad)?

I currently have a map view in my app that is locked so that the user can't interact with it (i.e. scroll, zoom etc.), however I want to make it into a UIButton. The idea being the the can press the map view and it will call a function, the same way pressing a UIButton does.
I've had a look around online for ideas on how to achieve this but I haven't found anything yet. I tried making a UIButton over the top of the map view but I can't seem to make it invisible. I also tried linking an IBAction to the map view, however the option to link it doesn't appear in the connections inspector (as I expected to be honest - shot in the dark!).
Is there any way to achieve this effect?
You can place a UIButton over the map, just like you tried before. But to make it invisible, change the button type from Round Rect to Custom. This will make the button invisible unless you explicitly add an image to the button.
-Cheers

UIButton disabled when covered (or semi covered) by a view

I have a view that holds some UIButtons. Another view covers and hides the buttons. When the top view slides off to reveal the buttons (with an animation).. the UI draws the buttons grayed out until the top view no longer covers or overlaps the buttons at all.. causing an undesirable flicker from gray to the normal button color (white).
is there a way to keep the UIButton from rendering itself disabled while covered or semi covered by another view?
I dont think that its correct that a button is disabled while covered. What is happening is that when its covered, touch events are prevented from getting to the button, so the button cant get pressed. If the button is only partially covered, touch events to that part that are not covered can be received by the button and the button can be depressed. If you really wanted the button to work while it was covered (maybe you can relayer your views so the button is in front of the view instead of behind it?) you could hack your view and void its hit testing so it doesnt capture the touches.
Well, in lieu of actually finding the correct answer, I simply swapped out the buttons with UIImageViews and attached UITapGestureRecognizers to them... this solved the problem.