Notifications in UIWebView that text selection has started or ended?

I am looking for a way to watch for notifications in UIWebView that text selection has begun or has ended. After tabs and blue highlighting appear, it automatically updates the Javascript selection and range objects, but when you exit the selection and end it, there seems to be no clean way to get notified.

+6
source share
1 answer

You can simply click on the javascript touchend event (or touchesEnded in Obj-C) and check the status of window.getSelection() . There is also a javascript selectionchange event.

Another method I use is to check the selection state of a UIWebView by looping through subviews:

 - (bool) selectionInWebView:(UIWebView*)webView { UIScrollView *scrollView = webView.scrollView; //assumes IO(6)? and scrollView is exposed. Loop subviews otherwise. UIView *browserView; for(int i = 0; scrollView.subviews.count; i++){ if([NSStringFromClass([scrollView.subviews[i] class]) isEqualToString:@"UIWebBrowserView"]){ browserView = scrollView.subviews[i]; break; } } if(browserView == nil) return false; for(int i = 0; browserView.subviews.count; i++){ if([NSStringFromClass([browserView.subviews[i] class]) isEqualToString:@"UIWebSelectionView"]){ //UIView *selectionView = browserView.subviews[i]; return true; //selection view exists, a selection is in progress } } return false; } 

But your best option is to check the status of the choice when a fire is triggered or a touch event change event occurs.

+1
source

All Articles