gpt4 book ai didi

ios - 无法正确配置 UIScrollView(Offset on top)

转载 作者:行者123 更新时间:2023-11-28 06:31:34 25 4
gpt4 key购买 nike

我整个上午都在为此苦苦挣扎,似乎找不到解决方案。我创建了一个 UIImageView,用红色填充它,然后将它添加到 UIScrollView 并将 contentSize 设置为 的大小UIImageView。如果我打印 contentOffset 我会看到 (0, 0) 如果我打印 contentSizeUIImageView.frame.size 它们是相同的,但红色“图像”总是显得比 scrollView 认为的 contentSize 小。

如果我一直滚动到顶部,我会看到红色图像上方约 100 像素高的青色条纹,并且滚动条不会一直滚动到我认为 ScrollView 顶部的顶部是。虽然滚动条的顶部确实与我的红色窗口的顶部对齐,所以 ScrollView 似乎对它实际所在的位置感到困惑。或者更有可能,我很困惑

IMG

这是我看似非常简单的代码...

    imgHorizon = UIImage.init(named:"horizon")!
imgBezel = UIImage.init(named:"bezel_transparent")!
imgWings = UIImage.init(named:"wings_transparent")!

imgViewHorizon = UIImageView.init()
imgViewBezel = UIImageView.init()
imgViewWings = UIImageView.init()

svHorizon = UIScrollView.init()

super.init(coder: aDecoder)

imgViewHorizon = UIImageView(frame: CGRect(x: 0, y: 0, width: imgBezel.size.width, height: imgHorizon.size.height))
imgViewHorizon.backgroundColor = UIColor.red

imgViewBezel = UIImageView(frame: CGRect(x: 0, y: 0, width: imgBezel.size.width, height: imgBezel.size.height))
imgViewBezel.contentMode = UIViewContentMode.center
imgViewBezel.clipsToBounds = true
imgViewBezel.image = imgBezel

imgViewWings = UIImageView(frame: CGRect(x: 0, y: 0, width: imgBezel.size.width, height: imgBezel.size.height))
imgViewWings.contentMode = UIViewContentMode.center
imgViewWings.clipsToBounds = true
imgViewWings.image = imgWings

svHorizon = UIScrollView(frame: CGRect(x: 0, y: 0, width: imgBezel.size.width, height: imgBezel.size.width))
svHorizon.contentSize = CGSize(width: imgBezel.size.width, height: imgHorizon.size.height)
svHorizon.contentMode = UIViewContentMode.scaleToFill
svHorizon.bounces = false
svHorizon.backgroundColor = UIColor.cyan
svHorizon.contentOffset = CGPoint(x: 0, y: 0)

svHorizon.addSubview(imgViewHorizon)
addSubview(svHorizon)
addSubview(imgViewBezel)
addSubview(imgViewWings)

最佳答案

从评论中的讨论可以看出,Adjust Scroll View Insets 选项已在 ViewController 的属性检查器中选中。取消选中它解决了问题。看看下面的图片。您需要取消选中突出显示的选项。

Attributes of the View Controller

关于ios - 无法正确配置 UIScrollView(Offset on top),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40184160/

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