Button Responsiveness at UIScrollView - ios

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.

Related

UIButton default tap animation inside UITableViewCell

I have a few UIButtons inside UITableViewCells, and all of them are missing default tap animation, however if I long press - animation works. I've found some solutions, like setting type to .system, showsTouchOnHighlight = true, but none of them have helped. What is the problem here?
It's not a "problem" - it's by design.
When you have an object such as a button in a table view or scroll view or collection view, and you "touch" it, the system needs to know whether you are tapping the button or if you want to touch-and-drag to scroll the view that contains the button.
So, the table view (really, the "scroll view part" of the table view), waits to see if you drag your finger or not before it performs any actions.
If you want the button to respond immediately to a touch, you need to set
delaysContentTouches = false
on the containing scroll view(s).
If you search for uibutton inside uitableviewcell delaysContentTouches you should find plenty of discussion on this topic, and various approaches to change the default behavior.
For this problem you can add extension to UIButton and override some methods.
You can check my answer here

How do I make the elements in my UIView responsive?

My goal is to create an alert that has three text fields, one taller than the others, and an image that, when tapped, allows the user to choose a picture to replace a set default one.
After unsuccessfully searching for a library for this, I decided to create my own alert by placing a UIView off the screen and, when prompted by a button, would zoom onto the screen; it consists of all the elements I require.
When I run the application, the view pops up correctly, but none of the elements on the view are responding to touch. I've checked that isUserInteractionEnabled for everything is turned on.
What's also odd is that when I keep the view on the screen (instead of placing it some distance away on Storyboard), all the elements work fine.
I'm assuming it had something to do with the animation. I tested it with a fade in instead of a displacement, and the result was the same - the elements were unresponsive.
In order for your elements to be responsive you have to link the action of you clicking them to your view's code. You can do this in a non-programmatic manner by ctrl-clicking your element on story-views and then dragging to the view controller. Then choose action instead of outlet, and choose when the action you want will be triggered (bottom part). Then insert your code in the viewController.
So I figured it out. I used the debug view hierarchy and saw that the alert was behind the elements behind it, even though it was still being shown (for some reason). I changed the zIndex of the UIView and it worked!

iOS: Making only one UIView to respond

I have several UIViews (CollectionView, TextField, etc) in my ViewController. If the user presses any item in the collectionview, a new collectionview (smaller) is to be shown from the bottom.When the new collectionView is being shown, I want only this view to respond to touch events. If the user taps outside this view, it should be taken off the viewController. The functionality is similar to PopOverController. I am using
[subCollectionView becomeFirstResponder]
but the other views are also responding to touch events.
I wish I could put the question more clearly, Let me know if it is not clear.
Thx!
No need of setting firstResponder of a UIView.
All you need to do is
create a view named bottomAnimateView(which will come from bottm) of size =
self.view.frame and background color as clear color.
add a UICollectionView over it.
3.Add UITapgesture over bottomAnimateView and do the stuff of removing or hidding it from superView.
Refer the attachment .Which might help you.

How to create a clickable button when it is below another view? (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.

UITextField not receiving touch event

I have a UITextField in a complex view hierarchy. The text field is in a UIView with label and textfield, say, labelfield.
I can type text there.
There is info button on top right corner. When tap on Info, a modal view controller is loaded. When coming back from the modal view controller, the UITextField becomes unresponsive. I cannt type anything there. The labelfiedl is drawn and shown in the screen.
Interesting thing is that, if I press the ok button, and alert is shown and then the textfield becomes active. Also, on top of the view, there is some text with user interaction enable, if I tap and try to select the text and after that the textfield becomes active. Seems I have to do some other activity/touch on the super view, then the text field becomes active.
Why not on the first case it receive any touch event? I tried with textField.enabled, becomesFirstResponder, setNeedsDisplay in the viewDidApper method, nothing works.
Try the following...
Make sure that the super view to which the text field is added as subview large enough to contain text field(ie make sure that no part of text field is out side the superview. check this for all views).
Make sure that there is no view above textfield.use bringSubViewToFront: method.
Try to enable use interaction after a delay
Hope any of the above fix will solve your problem

Resources