我们希望在Web视图的顶部实现本机栏,并希望为此原生栏提供视差效果。
请详细说明此原生条形视差是否适用于webview滚动
答案 0 :(得分:0)
要在webview顶部进行视差效果,您可以使用此library
import MXParallaxHeader
然后在viewController中添加以下行
var scrollView: MXScrollView!
并在viewDidLoad
// Parallax Header
scrollView = MXScrollView()
scrollView.parallaxHeader.view = Bundle.main.loadNibNamed("StarshipHeader", owner: self, options: nil)?.first as? UIView // You can set the parallax header view from a nib.
scrollView.parallaxHeader.height = 300
scrollView.parallaxHeader.mode = MXParallaxHeaderMode.fill
view.addSubview(scrollView)
webView = UIWebView()
scrollView.addSubview(webView)
然后在viewController
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
var frame = view.frame
scrollView.frame = frame
scrollView.contentSize = frame.size
frame.size.width = 2
frame.size.height -= scrollView.parallaxHeader.minimumHeight
webView.frame = frame
}
希望这会对你有所帮助