UIwebview does not respond to touchesBegan - ipad

I have subclass of UIViewController which has UIWebview as a subview added.
I'm trying to detect touch events on webview but failing to do so.
-(void)touchesBegan
is the method which should get called.
Can anyone help me in this.
Thanks in advance.

Detecting touches on UIWebView is not trivial.
Check this tutorial : http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/
BTW - If you need only to detect a touch on a links or buttons and add a custom action you can do it to. look here:
http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/
Good Luck

Make sure your UIWebView is the first responder. When you add it, use becomeFirstResponder on the web view (I've linked the documentation at Apple for you).
Also make sure becomeFirstResponder returns YES.
Lastly, make sure your view controller's UIView userInteractionEnabled property is set to YES.

Related

UIScrollView pass event to child chain on WillEndDragging

Edit: I am editing my initial question (see below for history) as I am getting new information.
I figured out that when the swipe motion starts from inside the button bounds, we never receive TouchesEnded or TouchesCancelled, only TouchesMoved. However, if I can react on WillEnddragging, it would be great. Is it possible to cancel a gesture on WillEndDragging and also pass this cancel down the children chain?
History:
I am using Xamarin Forms and I have the following issue
I have custom controls part of native scrolling views, like ScrollView or CollectionView, that remain in "clicked" state after the finger enters them but then initiates a scroll gesture.
I had a similar issue on UWP in the past and managed to solve it with the UIElement.PointerCaptureLost event.
Sorry if I am wasting your time on trivial stuff, but I am really stuck and I greatly appreciate your help.
I have tried different approaches suggested, including setting DelaysContentTouches to NO, and playing around with CanCancelContentTouches and overriding TouchesShouldCancelInContentView to always return NO, in a ScrollView custom renderer.
I have had a read of
Allow UIScrollView and its subviews to both respond to a touch
and
UIScrollView sending touches to subviews
Maybe the accepted answer here helps, but I am not sure how to get the tag of my custom view.
What I am expecting is my custom controls to receive the cancelled touch event (or something similar) as happens in both Android and Windows
This was easier than it looked. Solved by adding a UIGestureRecognizerDelegate to my UIGestureRecognizer class and in the delegate I overwrote ShouldRecognizeSimultaneously to return true.

How to make UITextView register touches when it is currently first responder?

I need a way to know when a UITextView is touched while it is first responder. I have seen some threads about this but I have never figured out how to make it work. I'm assuming there must be a way? Any input would be much appreciated thanks!
rc
UITextField is a subclass of UIControl, so you can add yourself as listener for events using addTarget:action:forControlEvents:.

Using a UIView as a button

I'm trying to use a UIView I've created in Storyboard as a button. I assumed it would be possible to use a UIButton, setting the type to custom. However I was unable to add subviews to a custom UIButton in Storyboard.
As such I've just spent the last hour reinventing the wheel by making my own custom gesture recoginizers to reimplement button functionality.
Surely this isn't the best way of doing it though, so my question - to more experienced iOS developers than myself - is what is the best way to make a custom button?
To be clear it needs to:
Use the UIView I've created as it's hittable area.
Be able to show a
different state depending on whether is currently highlighted or not
(i.e. touch down).
Perform some action when actually tapped.
Thank you for your help.
You can use a UIButton, set the type to custom, and then programmatically add your subviews...
Change your UIView into a UIControl in the storyboard. Then use the method [controlViewName addTarget:self action:#selector(*click handler method*) forControlEvents:UIControlEventTouchDown];. click handler method is a placeholder for the method name of your handler. Use this method except change out the UIControlEventTouchDown for UIControlEventTouchInside and UIControlEventTouchDragExit to call a method when the user finishes their click and drags their finger out of the view respectively. I used this for something I'm working on now and it works great.
In Touch down you will want to: highlight all subviews
In Touch up inside you will want to: unhighlight all subviews and perform segue or do whatever the button is supposed to do
In Touch Drag Exit you will want to: unhighlight all subviews
See second answer by LiCheng in this similiar SO post.
Subclass UIControl instead. You can add subviews to it and it can respond to actions
Why are you implementing your own GestureRecognizer? I recommend using the UIView so you can add subviews in the interface builder and adding a UITapGestureRecognizer. You can even do this graphically since you don't care about IOS4 support.

iOS subview not forwarding touches.

I have tried this a few different ways but none of them seem to work. I have a UIView subclass that has some buttons in it. I tried adding the subview to my ViewControllers however it will not respond to touches unless I set it to "initWithFrame:self.view.frame" but then it takes All of the touches and does not pass them to the view controller. I also tried adding it directly to the window so it's on top of all of the view however I have the same issue, either it will not accept touches or it takes them all.
here is how I add it when it takes all touches for itself and does not pass them on.
ControlView *cont = [[ControlView alloc]initWithFrame:self.window.frame];
[self.window addSubview:cont];
I'm so confused as to how to fix this and I have a lot more important tasks to work on but I have been stuck for two days with this stupid subview/touch issue.
How are you handling touches? UIGestureRecognizer?
You should make sure that your uiview subclass has userInteractionEnabled = YES. That's the default but maybe it got turned off somewhere along the line.

add UIPanGestureRecognizer to a UIView

I have 2 UIViews; let's call'em mainView and otherView. mainView uses the whole screen (it is an iPad app) and otherView is a smaller one that appears on top of mainView. The problem is that I don't know how and where to add the UIPanGestureRecognizer. The code snippets I find shows the code, but its never clear (or I'm not sure why it never works).
Most of the time I get a "otherView may not respond to +addGestureRecognizer" warning, I've tried adding the UIGestureRecognixerDelegate in practically all headers file and I don't know what I'm doing wrong.
Hope you can help me out :)
addGestureRecognizer is not a class method, it's an instance method. Other than that, without code there's not much I can say.
Also, check out CS193P Lecture 8: Gesture Recognizers. iTunes Link

Resources