gpt4 book ai didi

快速滚动条不滚动

转载 作者:行者123 更新时间:2023-11-30 12:35:30 25 4
gpt4 key购买 nike

我有一个 Swift 代码

    background_img_view.addSubview(background_image)
background_img_view.addSubview(usn)
profile_view.addSubview(PostsDiv)
profile_view.addSubview(PostDiv)
var scrollView: UIScrollView!
scrollView = UIScrollView(frame: view.bounds)
scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: 1500)
scrollView.autoresizingMask = UIViewAutoresizing.flexibleHeight
scrollView.isScrollEnabled = true
scrollView.addSubview(profile_view)
view.addSubview(background_img_view)
view.addSubview(scrollView)

我在手机上测试了这个,滚动条正在显示,但是当我滚动时没有任何变化,我也无法点击屏幕上的任何内容

最佳答案

您将所有内容锚定到背景图像的底部,但背景图像不在 ScrollView 中,因此滚动时不会发生任何移动。

您需要将 view.addSubview(background_img_view) 替换为 scrollView.addSubview(background_img_view)

您还需要将背景 ImageView 的顶部 anchor 和背景图像更改为scrollView的顶部。

替换:

background_img_view.anchor(view.topAnchor, left:view.leftAnchor, bottom: about.bottomAnchor, right: view.rightAnchor, topConstant: 60, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 280)
background_image.anchor(view.topAnchor, left:view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 60, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 280)

background_img_view.anchor(scrollView.topAnchor, left:view.leftAnchor, bottom: about.bottomAnchor, right: view.rightAnchor, topConstant: 60, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 280)
background_image.anchor(scrollView.topAnchor, left:view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 60, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 280)

关于快速滚动条不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42922126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com