How to pass events from UIView to WKWebview underneath? - ios

I have a WKWebview that I basically want to override the zooming behavior for. I want to scale up the font, so what I have right now is a UIView on top of the WKWebview that I've added a UIPinchGestureRecognizer to that does some evalutateJavascript call on the webview. However, now the Webview doesn't receive tapping or scrolling events as I believe the overlay view is capturing them. Is there a way to send it down to the webview? These are all in a single VC with outlets to both the webview and the overlay view. I wanted to override the behvaior directly for the WKWebview but I can't seem to get it to work.

Basically I know if you need to deliver gesture event to other responders, just set the pinchGestureRecognizer.cancelsTouchesInView = false

Related

Programmatically scroll in a UIWebView

I have a UIWebView which I want to perform a scroll programmatically. So say for instance if you press a UIButton it will scroll a few pixels down or so.
Would this be possible?
I think you should get UIScrollView of Webview first.
After that, you can control your UIScrollView.
https://github.com/marcuswestin/WebViewJavascriptBridge
https://github.com/newyankeecodeshop/GAJavaScript
use Native javascript using Objective-C function like windows.scrollTo(0,1000)
Scrolling inside a webview is controllable with JavaScript. Example using scrollTo:
With UIWebView (deprecated)
DispatchQueue.global().async {
_ = webView.stringByEvaluatingJavaScript(from: "window.scrollTo(0,100);")
}
With WKWebView (iOS 8+)
webView.evaluateJavaScript("window.scrollTo(0,100);")

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.

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.

UIWebView prevents UITableView to scroll

I have a cell in my UITableView with a UIWebView. The problem is that if you swipe on the UIWebView you swipe throughout the internet page, and not the table view. Since the web view has a hight of 500, it is possible that the user is stuck in the web view. Does anyone have any ideas in how to solve the problem?
Beginning with iOS 5, there is a scrollView property on UIWebView, so you can just do the following on your web view:
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
Then you should be able to scroll just fine. No need to disable interaction on the web view, unless you don't want the user to be able to interact with it at all.
If the user does not need to interact with the webview, you can set webview.userInteractionEnabled to NO.
If they need to interact with it, but don't need to scroll, you can set webview.scrollView.scrollEnabled to NO
Either of those solutions should allow scrolling to pass through to the tableView.
If they need to scroll the webview, I'd suggest rethinking your UI. AFAIK, Apple advises against having nested scrollviews.

How can you handle touching a link within a UIWebView when you have a UIView overlay directly on top of it?

I've been researching how to use a UIWebView embedded in a UIScrollView for a while now and cant seem to find an easy fix to my problem. I'm using a UIWebView because a UITextView, although allowing hyperlinks, does not allow you to change the link color from the standard blue apple sets.
But using a UIWebView introduces another problem: It blocks the UIScrollView it is embedded in from handling scroll events because a UIWebView handles these events within its own private implementation.
Although this allows me to use its embedded links, the UIWebView absorbs the touch events which doesn't allow me to scroll up/down when dragging within the UIWebView itself. I worked around this problem by placing a transparent UIView overlay exactly over the UIWebView, intercepting the touch events that it receives, and resigning it as first responder so that the UIScrollView that they are both subviews of can handle the scrolling appropriately.
Now, however, I can't seem to think of solution to the new problem this introduces: I can't click on the links within my UIWebView that is right under the UIView Overlay.
What is the best way to forward touch events to a UIWebView that is right underneath my transparent UIView in order to trigger my UIWebView's delegate method 'webView:shouldStartLoadWithRequest:navigationType:' for tapping on links?
FYI from UIWebView API doc:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Back to the question,
UIWebView has property called scrollView, try doing:
webView.scrollView.scrollEnable = NO;

Resources