【发布时间】:2018-03-16 12:49:59
【问题描述】:
我在 UICollectionViewCell 中有一个 UIImageView,我正在相对于滚动视图内容偏移进行移动。这一切都是为了在用户水平滚动时提供视差效果,但是当滚动视图开始滚动时似乎存在剪切问题。
边缘不会被剪裁,而是保留并显示在容器边界之外。
所附的屏幕截图最能展示这种行为...... 在屏幕截图中,滚动视图已经开始向右滚动,并且伴随的视图已经开始翻译,但是 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 属性的解释有关。
文档说明:
将此值设置为 true 会导致子视图被裁剪到边界 接收者。
我最初认为接收器是您将 UIImageView 附加到的视图,但事实并非如此。 有什么建议?
【问题讨论】:
标签: ios swift uiimageview