Setting contentInset of WKWebView scrollView causes page jump to top
up vote
0
down vote
favorite
After setting contentInset of WKWebView, I found if I use default swipe gesture to navigate between pages, WKWebView will not reserve the contentInset and just jump to the top, does anyone know how to resolve that? Thanks!

My sample code:
import UIKit
import WebKit
class ViewController: UIViewController {
private lazy var webView: WKWebView = {
let view = WKWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
view.allowsBackForwardNavigationGestures = true
view.scrollView.contentInsetAdjustmentBehavior = .never
view.scrollView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
view.navigationDelegate = self
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.addSubview(self.webView)
if let url = URL(string: "http://www.wikipedia.org") {
self.webView.load(URLRequest(url: url))
}
}
}
ios swift uiscrollview wkwebview
add a comment |
up vote
0
down vote
favorite
After setting contentInset of WKWebView, I found if I use default swipe gesture to navigate between pages, WKWebView will not reserve the contentInset and just jump to the top, does anyone know how to resolve that? Thanks!

My sample code:
import UIKit
import WebKit
class ViewController: UIViewController {
private lazy var webView: WKWebView = {
let view = WKWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
view.allowsBackForwardNavigationGestures = true
view.scrollView.contentInsetAdjustmentBehavior = .never
view.scrollView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
view.navigationDelegate = self
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.addSubview(self.webView)
if let url = URL(string: "http://www.wikipedia.org") {
self.webView.load(URLRequest(url: url))
}
}
}
ios swift uiscrollview wkwebview
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
After setting contentInset of WKWebView, I found if I use default swipe gesture to navigate between pages, WKWebView will not reserve the contentInset and just jump to the top, does anyone know how to resolve that? Thanks!

My sample code:
import UIKit
import WebKit
class ViewController: UIViewController {
private lazy var webView: WKWebView = {
let view = WKWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
view.allowsBackForwardNavigationGestures = true
view.scrollView.contentInsetAdjustmentBehavior = .never
view.scrollView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
view.navigationDelegate = self
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.addSubview(self.webView)
if let url = URL(string: "http://www.wikipedia.org") {
self.webView.load(URLRequest(url: url))
}
}
}
ios swift uiscrollview wkwebview
After setting contentInset of WKWebView, I found if I use default swipe gesture to navigate between pages, WKWebView will not reserve the contentInset and just jump to the top, does anyone know how to resolve that? Thanks!

My sample code:
import UIKit
import WebKit
class ViewController: UIViewController {
private lazy var webView: WKWebView = {
let view = WKWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
view.allowsBackForwardNavigationGestures = true
view.scrollView.contentInsetAdjustmentBehavior = .never
view.scrollView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
view.navigationDelegate = self
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.addSubview(self.webView)
if let url = URL(string: "http://www.wikipedia.org") {
self.webView.load(URLRequest(url: url))
}
}
}
ios swift uiscrollview wkwebview
ios swift uiscrollview wkwebview
asked Nov 19 at 12:00
Haibara Ai
7,67721438
7,67721438
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374195%2fsetting-contentinset-of-wkwebview-scrollview-causes-page-jump-to-top%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
