ScrollView issue Swift

2019-09-09 09:37发布

I have a view controller with a inside scrollview , but when I load the view controller the its scrollview isn't start from top but its almost at half screen , like this:

enter image description here

The view controller is in pageviewcontroller but I think that its not important. I dont poste the code because I think that its not important in this case , but if its i will post it.

I tried to print the contentOffset but I get (0.0, 0.0)

2条回答
劳资没心,怎么记你
2楼-- · 2019-09-09 10:24

Add a UIView named "BgView" inside ScrollView(total scroll size) and give constraints.

enter image description here

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    scrollView.layoutIfNeeded()
    scrollView.contentSize = bgView.bounds.size
}
查看更多
爷、活的狠高调
3楼-- · 2019-09-09 10:35

I had the same issue, And i fixed it by adding one UIView before UIScrollView ... Find the below image ...

enter image description here

查看更多
登录 后发表回答