From 20451148a5b09eddaf3c5919796b54618d045ac6 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Tue, 26 May 2015 10:17:45 -0700 Subject: [PATCH] require a selector to load the request --- SCDomElementView/SCDomElementView.swift | 20 ++++++++++++-------- iOS Example/iOS Example/ViewController.swift | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/SCDomElementView/SCDomElementView.swift b/SCDomElementView/SCDomElementView.swift index 77474a6..ff63618 100644 --- a/SCDomElementView/SCDomElementView.swift +++ b/SCDomElementView/SCDomElementView.swift @@ -34,6 +34,7 @@ public class SCDomElementView: UIView, WKNavigationDelegate, UIScrollViewDelegat }() public var delegate: SCDomElementViewDelegate? + private var selector: String? public override init(frame: CGRect) { super.init(frame: frame) @@ -73,21 +74,24 @@ public class SCDomElementView: UIView, WKNavigationDelegate, UIScrollViewDelegat } } - public func loadRequest(request: NSURLRequest) { + public func showSelector(selector: String, withRequest request: NSURLRequest) { + self.selector = selector delegate?.domElementViewDidStartRequest(self) webView.loadRequest(request) } public func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) { - self.rectFromId("mobile") { rect in - var frame = rect - self.webView.scrollView.contentInset = UIEdgeInsets(top: -frame.origin.y, left: -frame.origin.x, bottom: (frame.origin.y + frame.size.height), right: (frame.origin.x + frame.size.width)) + if let selector = selector { + self.rectFromId(selector) { rect in + var frame = rect + self.webView.scrollView.contentInset = UIEdgeInsets(top: -frame.origin.y, left: -frame.origin.x, bottom: (frame.origin.y + frame.size.height), right: (frame.origin.x + frame.size.width)) - frame.origin = CGPointZero - self.frame = frame - self.webView.frame = frame + frame.origin = CGPointZero + self.frame = frame + self.webView.frame = frame - self.delegate?.domElementViewDidFinishRequest(self) + self.delegate?.domElementViewDidFinishRequest(self) + } } } } diff --git a/iOS Example/iOS Example/ViewController.swift b/iOS Example/iOS Example/ViewController.swift index 68922c2..5b0e3e4 100644 --- a/iOS Example/iOS Example/ViewController.swift +++ b/iOS Example/iOS Example/ViewController.swift @@ -22,7 +22,7 @@ class ViewController: UIViewController { let request = NSMutableURLRequest(URL: nsUrl, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: 30) request.setValue("f28f3d351d03e881478ef0f3aae47113", forHTTPHeaderField: "OPAL-AUTH-TOKEN") - elementView.loadRequest(request) + elementView.showSelector("mobile", withRequest: request) } }