Ajwhiteway Ajwhiteway - 5 months ago 55
Swift Question

iOS SWIFT Showing hidden view really slow

so I have a setup as such:

self.webView = WKWebView(frame: frame, configuration: WKWebViewConfiguration())
self.externView = UIView(frame: frame)
self.externWebView = WKWebView(frame: subFrame, configuration: WKWebViewConfiguration())
let StackView = UIStackView(frame: frame)


self.externView?.addSubview(StackView)
self.externView?.backgroundColor = UIColor.blackColor()

view.addSubview(self.webView!)
self.externView?.hidden = true
StackView.addSubview(self.externWebView!)
view.addSubview(self.externView!)


This creates the initial setup I want, this allows for 1 web view to act as the main one, which can launch and external one to render something else, that is initially hidden.

The problem I'm running into, is that from a worker thread I'm calling

WKExteralLoader.externView!.hidden = false;
WKExteralLoader.webView!.hidden = true;


which can take up to 30 seconds to take effect; however, its inverse is nearly instantaneous.

WKExteralLoader.webView!.hidden = false;
WKExteralLoader.externView!.hidden = true;


Any ideas what could cause this problem?

Thanks!

Answer

Run the hide/show code on the UI thread

 dispatch_async(dispatch_get_main_queue()) {
        WKExteralLoader.webView!.hidden = false;
        WKExteralLoader.externView!.hidden = true;
    }