【发布时间】:2016-02-19 07:43:56
【问题描述】:
我试图覆盖原来的 wkwebview actionsheet...
首先我禁用了 webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';", completionHandler: nil) 的原始 wkactionsheet
然后我初始化了一个长按手势识别器(它工作得很好)并创建了我自己的操作表。我使用了 decisionPolicyForNavigationAction 来获取点击的链接网址:
func onLongPress(gestureRecognizer:UIGestureRecognizer){
if gestureRecognizer.state == UIGestureRecognizerState.Began {
longPressSwitch = true
}
}
func webView(webView: WKWebView, decidePolicyForNavigationAction navigationAction: WKNavigationAction, decisionHandler: (WKNavigationActionPolicy) -> Void) {
if(navigationAction.navigationType == .LinkActivated) {
longPressAcUrl = navigationAction.request.URL!.absoluteString
if(longPressSwitch == true) {
let ac = actionMenu(self)
self.presentViewController(ac, animated: true) {
}
decisionHandler(.Cancel)
longPressSwitch = false
}
}
decisionHandler(.Allow)
}
问题是,操作表在手指释放后显示(即 recogniser.state = .Ended),但我希望它像 Chrome 一样显示,这应该在用户按下链接后 0.5 秒或更短的时间内显示。 ..(即recogniser.state = .Begin),我该怎么办?
ps:这是我的行动表:
//Rebuild Wkactionsheet
func actionMenu(sender: UIViewController) -> UIAlertController {
let alertController = UIAlertController(title: "", message: longPressAcUrl, preferredStyle: .ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
}
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open", style: .Default) { (action) in
//...
}
alertController.addAction(openAction)
let opentabAction = UIAlertAction(title: "Open in New Tab", style: .Default) { (action) in
//...
}
alertController.addAction(opentabAction)
let copyurlAction = UIAlertAction(title: "Copy Link URL", style: .Default) { (action) in
//...
}
alertController.addAction(copyurlAction)
return alertController
}
另外,如果我试着把
let ac = actionMenu(self)
self.presentViewController(ac, animated: true) {}
在 onLongPress() 处,虽然无法从 navigationAction.request.URL!.absoluteString! 获取 URL (longPressAcUrl),但它工作正常!
【问题讨论】:
标签: ios swift uigesturerecognizer wkwebview uilongpressgesturerecogni