views:

71

answers:

1

How do we get the on-screen location of a selection in UIWebView? That is whenever the user selects some text and the system displays the selection box, I want to know what is the bounding coordinate of the rectangle in screen (or view) units.

The reason for this that I want to display a UIPopoverController that has an arrow pointing to the selection rectangle.

I've tried getting the selection via the JavaScript call window.getSelection() but it seems that both the resulting Selection and Range JavaScript objects could not point to the exact screen (or document) relative point (pixel) coordinate since they are not atomic DOM nodes.

Thanks.

A: 

You can't get the physical location of the highlighted range of text from a UIWebView.

The reason for this that I want to display a UIPopoverController that has an arrow pointing to the selection rectangle.

That is not what UIPopoverController is for. This is non-standard so it will confuse users and might get you rejected by Apple in the approval process.

Shaggy Frog
I presume you had your app rejected for this? Note that this is standard UI in desktop Safari (select a word and press Cmd+Ctrl+D and you'll get a dictionary definition of the selected word -- I want to get the same effect on an iPad).
adib
I have not had my app rejected for this -- but I would bet money that using it simply as an "arrow pointing to the selection rectangle" would cause rejection. A `UIPopoverController` should contain content related to the control to which it's pointing. As for "desktop Safari" doing something, that has really no bearing on what Apple can impose for iOS.
Shaggy Frog
@Shaggy Frog: but it does point to the related content -- a dictionary points to the word being looked up.
adib
Well, if your popover has actual content, then that's probably not an issue. Doesn't change the original problem, though, which is getting screen coordinates for a selection range, which you can't get from the underlying class.
Shaggy Frog