ios - Getting caret (cursor) vertical position in a UIWebView -


In order to manage the automatic scrolling in a content editable UIWebView, I need to get the right carat Y vertical coordination.

I identified two methods, using javascript

Javascript function first uses a getClientRects: .

  CGRect caretRect = [self. WebView stringByEvaluatingJavaScriptFromString: @ "sel = document.getSelection (); Range at sel.getRangeAt (0) .cloneRange (); range.collapse (true); r = range.getClientRects () [0]; return '{ {'+ R.left +', '+ r.top +'} {'+ r.width +', '+ r.height +'}} ',']; Int Carit Y = Carat Detector With this, the caret keeps blinking and one gets its right vertical position with a problem: when the user type returns key, so that the next row is empty, the carti is equal to zero The character key is typed. That is why this method can not be used.  

Enter the second one TMP period, then deletes it :

  int caretY = [[self.webView stringByEvaluatingJavaScriptFromString: @ "on Sel = window.getSelection (); sel.collapseToStart (); range = sel.getRangeAt (0); above period = document.createElement (\ "period \"); range.insertNode (time); var toppage = span. OffsetTop; span.parentNode.removeChild (span); top post, "] intValue];  

This gives correct carat in any situation. But the carat blinking stops, which is extremely irrelevant to see it on the screen.

Does anyone know any method (or adaptations to them) that can do the following:

  - Get the right carat yah in any situation - anyone  

Thank you

Not sure if the carpet blinking in position That it is too late;

  function getCaretY () {var y = 0;  

Add getCaretY () to your JS file below. Var sel = window.getSelection (); If (sel.rangeCount) {var category = sel.getRangeAt (0); If (range.getClientRects) {var rects = range.getClientRects (); If (rects.length & gt; 0) {y = rects [0] .top; }}} Return y; }

Then it says the Obj c file to the following:

  NSString * yPos = [WebView stringByEvaluatingJavaScriptFromString: @ "getCaretY ()"];  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -