2015-10-01 40 views
0

我正试图在WkWebView中实现自定义窥视/弹出行为。 我看到被调用的委托和控制器被返回,但peek控制器不显示。自定义3D触摸和WkWebView问题

我只能得到偷看控制器showup通过设置 self.webView?.userInteractionEnabled =假

什么可怎么回事呢?

代码:

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. 

} 
} 
+0

我看到它正在试图加载控制器,但它一直没有出现.... –

回答

0

设置一个prefferedContentSize高度

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