cocoa-touch - iPad UIWebView 将 UIPopoverController View 定位在 href 链接坐标处

标签 cocoa-touch ipad uiwebview uipopovercontroller

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

我正在使用委托(delegate)方法;

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

}

捕获和路由点击,但我不确定如何获取链接坐标来定位弹出 View 。

非常感谢任何帮助或指向相关信息的指针。

最佳答案

我有一个可行的解决方案,但我认为有更好的方法来做到这一点。

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

@interface TouchableWebView : UIWebView {
CGPoint lastTouchPosition;
}
@property (nonatomic, assign) CGPoint lastTouchPosition;

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];
}

在 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;
}

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

关于cocoa-touch - iPad UIWebView 将 UIPopoverController View 定位在 href 链接坐标处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3118401/

相关文章:

ios - 适用于 iOS 的 Facebook Photo Picker Controller(类似于 Places Picker Controller )

ios - 识别在iOS的WebView中播放的youtube视频网址?

iphone - CATransform3D 与 CGAffineTransform?

iphone - 调用存在于多个类中的方法的最佳方法

iphone - 特定屏幕上的 iOS Laggy UI

iphone - 如何根据拖动角边的比例调整 UIView 的大小?

javascript - facebook like 按钮未显示在 webview 中(ios 和 android)

ios - 如何更改 WKWebView swift 5 中的字体大小?

iphone - 使用 NSOperationQueue 跟踪下载

objective-c - iOS 7 碰撞发生后添加 UIGravityBehavior 和 UIPushBehavior