Detecting when an open selection widget opens / closes in a UIWebView

When a user clicks on the select field in UIWebView , a list of available attributes with available parameters is displayed at the bottom of the screen. The contents of the web page scroll up to make room for this popover.

It does not appear that the DOM event is fired when this scroll is performed, although the value of body.scrollTop changes. Is there a way to detect when a popover opens, or do we need to use setInterval to poll and view scrollTop changes?

+8
javascript ios scroll uiwebview
source share
2 answers

I am surprised that the scroll event does not fire. MDN has a list of events that may be related to what may help you.

The quick thought that jumps out of me is that you can snap to the mouse, and the input / change events in the selection and in its callbacks determine that scrollTop when the user interacts with the selection. If you have several samples that you need to track, you can delegate events to the body to avoid creating additional listeners.

The survey will work, but it would be much less effective than adding a few event listeners to the choice itself, so I hope you can find an event that works.

Hope this helps!

+3
source share

You can achieve this by installing a listener in UIPicker using a WebView delegate. This listener can then call the appropriate function in your JS:

 class ViewController: UIViewController, UIWebViewDelegate { @IBOutlet weak var webView: UIWebView! ... // UIWebViewDelegate protocol for WebView load func webViewDidFinishLoad(webView: UIWebView!) { // Set observer for keyboard load event NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) } func keyboardWillShow(sender: NSNotification){ // Call JavaScript function in the WebView webView.stringByEvaluatingJavaScriptFromString("yourJSFunction()") } } 
0
source share

All Articles