How to create a clickable button when it is below another view? (iOS) - ios

My ViewController contains WebView and invisible button over (or below) the WebView. (see image). I want that the button to be clickable. But(!) in the case there are some links in the WebView, the links should be clicked, not the button.
How can I do it?
Similar issue discussed here:
Add UIButton in a UIWebView
However, in my case, I need links that are clickable also not be scrolling enabled.

If all you need is to be able to still drag the UIWebView around while still being able to receive a button press on a certain part on the view, you don't need to place a button below it in order to achieve that.
UIButton can still be able to receive touch even if it is completely transparent.
yourButton.backgroundColor = [UIColor clearColor];
[yourButton addTarget:self action:#selector(pressed)forControlEvents:UIControlEventTouchUpInside];
This way the button would only receive the press and will not affect your dragging of the web view - it will ignore the dragging but respond only to the press.
Tested on a scrollable view with a clear UIButton.
Hope this helps.

Related

Disable button interaction if below another view

I'd like to disable a button interaction if it is below another view.
On this example, my UIButton is the green frame.
I can tap on it and it will call the right selector (with control event "UIControlEventTouchUpInside"). But this call also work if I tap on the red frame which is above the green button, and I don't want that...
Any help to disable the interaction where the button isn't visible?
Fixed by setting :
theUpperView.userInteractionEnabled = YES;

Button Responsiveness at UIScrollView

I am dynamically creating a uiscrollview and i place some uiview's that contains some label and buttons inside to display some news. Every button inside the sub uiview calls a rest function to like, unlike or share the news. Some of the buttons opens overlay screens like comment news. I am assigning actions to buttons inside the main form that contains the uiscrollview.
When i click a button that opens an overlay screen. When i close the overlay screen and hit Like button, it does not respond to touches. After attempting one or two more times, it works.
Does anyone has any idea about this issue?
Are you using UITapGestureRecogniser for "Click action"? If yes, you propably want to set flag "cancelsTouchesInView = NO" for this recogniser.
Check to see if there is a clear view covering your button. That view will consume your tap, so the button never sees it.

Content Editable UIWebView scrolls and overlaps over the button/images of uiview in iOS

I have a view with few buttons and UIWebView which loaded content editable HTML.
In UIWebView i am inserting images/Canvas using both native and javascript functionality.
Since the WebView is editable whenever webview is clicked keyboard comes up. Now when we are inserting/editing a image/canvas keyboard should hide. So for that i am checking for tap event, getting the id of the element at that position and hiding the keyboard if that is a image/canvas using [webview endEditing:YES];.
Now the problem what i am facing is that if i add 2-3 images and then clicks on the webview, webview starts moving from its position and overlaps the button/images kept at the uiview. So the button are not visible and i am not able to perform the actions related to that.
Issue resolved. I was using some kind of animation when the keyboard was show/hidden. Once i removed that uiwebview doesn't moves.

Button remains visible when disabled

I have created a custom button in IB which performs a play video function for me. But sometimes when the video is not available I want to have the button disabled & invisible.
the button is linked to the code by having dragged the IBOutlet.
so when I do [playButton setEnabled:NO] it gets disabled, but it's still visible, although becomes transparent. I need it completely disappeared. Any ideas?
Set playButton.hidden = YES to hide it.
Disabling only prevents user interaction

How do I make the keyboard go away when the user clicks somewhere else? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Dismiss keyboard by touching background of UITableView
How do I make the keyboard go away when the user clicks somewhere else?
Note: I know how to make the keyboard disappear with sending the resignFirstResponder command to the UITextField. At present the "Done" button is connected to all the correct code to do this and this works.
I have a UITableView with different UITableViewCells, and if the user moves onto another cell I want the keyboard to disappear.
So what events do I also need to include the resignFirstResponder in, for the keyboard to disappear.
Suppose UITableViewCell A has the UITextField, and UITableViewCell B has a button. If the user presses the button in cell B, then I will need to send the command resignFirstResponder back to the UITextField in cell A. First of all the button has no idea which cell it should sent the command to, and second even if the button did know which cell to send the command to how would it?
There's no trivial way to do this. You can put a transparent set of "shield views" all the way around the text field that take up the rest of the screen, and use any touches on them to dismiss the keyboard.
You can create a generic 'hideKeyboard' method in which you can include all text fields that can be first responders. For example,
-(void) hideKeyboard {
[textFieldName resignFirstResponder];
[textFieldSurname resignFirstResponder];
for (UITextField * txtField in arrTextFields) {
[txtField resignFirstResponder];
}
}
Then, at various sections in your class, depending on the functionality required, call;
[self hideKeyBoard];
This simple method means you won't need to keep track of the individual item that 'has the focus' / first responder status.
How to touch any part of the screen to make the keyboard go away
To touch somewhere outside the UITableView and have the keyboard disappear, place an invisible button on top of the 'touch area' that you want to respond to. Then, simply call [self hideKeyboard] from the touch event for that invisible button. Using IB, drag a new rounded button onto your view, then size it to take up the full size of the screen. Next,drag the button up or down the controls list in the IB document window so that button is behind all text fields and buttons, but in front of anything else (like images etc.). Finally, change the type of the button to 'Custom' to make it invisible, but still respond to events. Now all you have to do is to connect the new button's 'touch up inside' event to trigger the 'hideKeyboard' method.
Additionally, see this post for a brilliant solution to dismiss the keyboard when the above solution doesn't work : stackoverflow question 1823317

Resources