gpt4 book ai didi

ios - 自定义 3D touch 和 WkWebView 问题

转载 作者:行者123 更新时间:2023-11-30 14:02:04 27 4
gpt4 key购买 nike

我正在尝试在 WkWebView 中实现自定义查看/弹出行为。我看到委托(delegate)被调用并且 Controller 被返回,但是 peek Controller 没有显示。

我只能通过设置来显示窥视 Controller self.webView?.userInteractionEnabled = false

这里可能发生了什么?

代码:

class ViewController: UIViewController, WKNavigationDelegate, UIViewControllerPreviewingDelegate {

var webView: WKWebView?

func webView(webView: WKWebView,
decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse,
decisionHandler: ((WKNavigationResponsePolicy) -> Void)){

decisionHandler(.Allow)
}

override func viewDidLoad() {
super.viewDidLoad()

/* Create our preferences on how the web page should be loaded */
let preferences = WKPreferences()
preferences.javaScriptEnabled = true

/* Create a configuration for our preferences */
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences

/* Now instantiate the web view */
webView = WKWebView(frame: view.bounds, configuration: configuration)

if let theWebView = webView{
/* Load a web page into our web view */
let url = NSURL(string: "http://www.apple.com")
let urlRequest = NSURLRequest(URL: url!)
theWebView.loadRequest(urlRequest)
theWebView.navigationDelegate = self
view.addSubview(theWebView)

}

self.registerForPreviewingWithDelegate(self, sourceView: self.view)
}

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {

self.webView?.userInteractionEnabled = false
let peekViewController = storyboard!.instantiateViewControllerWithIdentifier("peekaboo") as UIViewController
/*
Set the height of the preview by setting the preferred content size of the detail view controller.
Width should be zero, because it's not used in portrait.
*/
peekViewController.preferredContentSize = CGSize(width: 0.0, height: 0.0)

// Set the source rect to the cell frame, so surrounding elements are blurred.
//previewingContext.sourceRect = (self.webkitWebView?.frame)!

return peekViewController
}

/// Present the view controller for the "Pop" action.
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
// Reuse the "Peek" view controller for presentation.

}
}

最佳答案

设置 prefferedContentSize 高度

peekViewController.preferredContentSize = CGSize(width: 0.0, height: 150)

关于ios - 自定义 3D touch 和 WkWebView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878265/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com