如何在旋转时使图像充满collectionviewcell? 收集单元中的初始化代码:
override init(frame: CGRect) {
super.init(frame: frame)
let imageView = UIImageView(frame: contentView.frame)
imageView.image = #imageLiteral(resourceName: "images")
imageView.contentMode = .scaleAspectFill
imageView.adjustsImageSizeForAccessibilityContentSizeCategory = false
imageView.clipsToBounds = true
contentView.addSubview(imageView)
contentView.addSubview(titleLabel)
let guide = contentView.layoutMarginsGuide
imageView.centerXAnchor.constraint(equalTo: guide.centerXAnchor).isActive = true
imageView.rightAnchor.constraint(equalTo: guide.rightAnchor).isActive = true
imageView.leftAnchor.constraint(equalTo: guide.leftAnchor).isActive = true
imageView.widthAnchor.constraint(equalTo: guide.widthAnchor).isActive = true
//title.topAnchor.constraint(equalTo: guide.topAnchor, constant: 10).isActive = true
//title.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 10).isActive = true
}
答案 0 :(得分:0)
collectionView.invalidateLayout()