Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have a solution that works but I think there is a better way to do it.</p> <p>I created a TouchableWebView that inherits from UIWebView and the save the touch position in the method hitTest. After that, you need to set a delegate for your webview and implement the method <code>-webView:shouldStartLoadWithRequest:navigationType:</code></p> <p>TouchableWebView.h :</p> <pre><code>@interface TouchableWebView : UIWebView { CGPoint lastTouchPosition; } @property (nonatomic, assign) CGPoint lastTouchPosition; </code></pre> <p>TouchableWebView.m :</p> <pre><code>// I need to retrieve the touch position in order to position the popover - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { self.lastTouchPosition = point; return [super hitTest:point withEvent:event]; } </code></pre> <p>In RootViewController.m :</p> <pre><code>[self.touchableWebView setDelegate:self]; // WebView delegate, when hyperlink clicked - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if (navigationType == UIWebViewNavigationTypeLinkClicked) { CGPoint touchPosition = [self.view convertPoint:self.touchableWebView.lastTouchPosition fromView:self.touchableWebView]; [self displayPopOver:request atPosition:touchPosition isOnCelebrityFrame:FALSE]; return FALSE; } return TRUE; } </code></pre> <p>It's not good because documentation of <a href="http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UIWebView_Class/Reference/Reference.html" rel="nofollow noreferrer"><code>UIWebView</code></a> says that you shouldn't subclass it. I guess there is a nicer way but this does work. Did you find another solution ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload