gpt4 book ai didi

ios - UIImageView 在动画时不剪裁到 UIView 边界

转载 作者:搜寻专家 更新时间:2023-11-01 06:31:36 25 4
gpt4 key购买 nike

我在 UICollectionViewCell 中有一个 UIImageView,我正在相对于 ScrollView 内容偏移移动它。这一切都是为了在用户水平滚动时提供视差效果,但是当 ScrollView 开始滚动时似乎存在裁剪问题。

边缘不会裁剪,而是会保留并显示在容器边界之外。

所附的屏幕截图最好地展示了行为...... enter image description here在屏幕截图中, ScrollView 已开始向右滚动,伴随的 View 已开始平移,但 UIImageView 尚未剪裁其边框以匹配接收器。在这种情况下,它应该是透明的 UIView。

这是 UIImageView

let cellImage: UIImageView = {
let c = UIImageView()
c.clipsToBounds = true
c.layer.masksToBounds = true
c.contentMode = .scaleAspectFill
c.image = UIImage(named: "tree")
c.translatesAutoresizingMaskIntoConstraints = false
c.layer.cornerRadius = 15
return c
}()

然后将 UIImageView 添加到 containerView 并设置为填充它的边界。

cellContainerView.addSubview(cellImage)
//add constraints

我的想法是,这个问题可能与我对 .clipsToBounds 属性作用的解释有关。

文档指出:

Setting this value to true causes subviews to be clipped to the bounds of the receiver.

我最初认为接收器是您将 UIImageView 附加到的 View ,但事实并非如此。有什么建议么?

最佳答案

如文档所述:

Setting this value to true causes subviews to be clipped to the bounds of the receiver.

目前您正在 cellImage 上设置此属性,因此在本例中它是接收器,因此它的 subview 将被剪裁。但是你想剪裁这个 ImageView ,所以我认为你需要在 cellContainerView 上设置这个属性,因为你想剪裁它的 subview 。

关于ios - UIImageView 在动画时不剪裁到 UIView 边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46576508/

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