iPad UIWebView在href链接坐标上定位UIPopoverController视图

and*_*com 4 cocoa-touch uiwebview ipad uipopovercontroller

我希望这个问题不是一个愚蠢的问题,但是如何在UIWebView上定位UIPopoverController视图,以便弹出视图箭头指向被点击以显示它的UIWebView链接?

我正在使用委托方法;

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( [[[inRequest URL] absoluteString] hasPrefix:@"myscheme:"] ) {
//UIPopoverController stuff here
return NO;
}
Run Code Online (Sandbox Code Playgroud)

}

捕获和路由点击但我不确定如何获得链接坐标定位弹出视图.

任何帮助或指向相关信息的指针都将非常感激.

Ced*_*rie 7

我有一个有效的解决方案,但我认为有更好的方法.

我创建了一个继承自UIWebView的TouchableWebView,并在方法hitTest中保存触摸位置.之后,您需要为webview设置委托并实现该方法-webView:shouldStartLoadWithRequest:navigationType:

TouchableWebView.h:

@interface TouchableWebView : UIWebView {
CGPoint lastTouchPosition;
}
@property (nonatomic, assign) CGPoint lastTouchPosition;
Run Code Online (Sandbox Code Playgroud)

TouchableWebView.m:

// 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];
}
Run Code Online (Sandbox Code Playgroud)

在RootViewController.m中:

[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;
}
Run Code Online (Sandbox Code Playgroud)

它并不好,因为文档UIWebView说你不应该继承它.我想有一个更好的方法,但这确实有效.你找到了另一种解决方案吗