为什么 UIImageView 在其内容模式为 .scaleAspectFill 时在纵向图片中超出其限制?
Why UIImageView when its content mode is .scaleAspectFill in portrait pictures goes over its constraints?
我正在使用 ImageView 和 CollectionView 创建图片库。一切正常,但肖像模式图片超出了限制。这是为什么?
myPicture = UIImageView(image: myArray[0])
view.addSubview(myPicture)
myPicture.translatesAutoresizingMaskIntoConstraints = false
myPicture.contentMode = .scaleAspectFill
myPicture.topAnchor.constraint(equalTo: tabBar.bottomAnchor, constant: view.bounds.height / 80).isActive = true
myPicture.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
myPicture.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
myPicture.bottomAnchor.constraint(equalTo: collectionView.topAnchor, constant: 0).isActive = true
您需要设置
myPicture.clipsToBounds = true
我正在使用 ImageView 和 CollectionView 创建图片库。一切正常,但肖像模式图片超出了限制。这是为什么?
myPicture = UIImageView(image: myArray[0])
view.addSubview(myPicture)
myPicture.translatesAutoresizingMaskIntoConstraints = false
myPicture.contentMode = .scaleAspectFill
myPicture.topAnchor.constraint(equalTo: tabBar.bottomAnchor, constant: view.bounds.height / 80).isActive = true
myPicture.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
myPicture.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
myPicture.bottomAnchor.constraint(equalTo: collectionView.topAnchor, constant: 0).isActive = true
您需要设置
myPicture.clipsToBounds = true