gpt4 book ai didi

ios - 在 Swift iOS 中,为什么两个相同大小的嵌套 UIImageView 大小不同?

转载 作者:行者123 更新时间:2023-11-29 02:11:00 24 4
gpt4 key购买 nike

我正在尝试解决一些处理 UIImageViews 的 AutoLayout 问题。你能确定为什么会出现以下代码吗:

    var image : UIImage = UIImage(named:"cat1.jpg")!
var catView1 = UIImageView(image: image)
catView1.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
catView1.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(catView1)

var image2 : UIImage = UIImage(named:"cat1.jpg")!
var catView2 = UIImageView(image: image2)
catView2.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
//catView2.setTranslatesAutoresizingMaskIntoConstraints(false)
catView1.addSubview(catView2)

//Why are these two different views not the same size?

看起来像这样:

enter image description here

这两张图片不应该一样大吗?我只是没有得到我猜的面具的东西。

这是项目: http://fm001-forumimages.s3.amazonaws.com/CenterConstraint3.zip

最佳答案

设置 translates... = false 允许 UIImageView 找到它的自然尺寸,这将是图像的尺寸,覆盖您的 100x100 尺寸已经任意设置了。

关于ios - 在 Swift iOS 中,为什么两个相同大小的嵌套 UIImageView 大小不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29289188/

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