我希望这个问题不是一个愚蠢的问题,但是如何在UIWebView上定位UIPopoverController视图,以便弹出视图箭头指向被点击以显示它的UIWebView链接?
我正在使用委托方法;
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { if ( [[[inRequest URL] absoluteString] hasPrefix:@"myscheme:"] ) { //UIPopoverController stuff here return NO; }
}
捕获和路由点击但我不确定如何获得链接坐标定位弹出视图.
任何帮助或指向相关信息的指针都将非常感激.
解决方法
我有一个有效的解决方案,但我认为有更好的方法.
我创建了一个从UIWebView继承的TouchableWebView,并在方法hitTest中保存触摸位置.之后,您需要为webview设置委托并实现方法-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
的文档说你不应该继承它.我想有一个更好的方法,但这确实有效.你找到了另一种解决方案吗
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。