我已经使用AutoLayout设置了UIImageView。我已经为顶部,底部,顶部和尾部设置了限制(我希望根据手机的大小改变宽度和高度)。在我的属性检查器中,它还显示图像视图的宽度和高度。出于某种原因,当第一次加载视图时,顶部空间到顶部布局约束被忽略,图像离开屏幕,并且IB的高度被使用(332)。添加照片后,视图会按预期调整大小。我NSLogged图像视图的帧高度,它正在改变。我不明白,我认为图像视图的FRAME总是一样的。我没有收到任何自动布局错误,一切都是蓝色的。 UIImageView使用AutoLayout更改帧大小
UIImage *imageToView = [existingImage resizedImageWithBounds:self.selectPhoto.frame.size];//Resize the image for better performance
self.selectPhoto.contentMode =UIViewContentModeScaleAspectFit;
NSLog(@"Select Photo Frame Size Height is %f", self.selectPhoto.frame.size.height); //The first time this screen loads, this height is 332. Every other time (after the user enters a new photo, the height is 310 which is what I want.
self.selectPhoto.image = imageToView;
回顾:为什么我的self.selectPhoto(这是在屏幕截图中显示的大图像视图).frame变化?我仔细检查了Apple Docs,并没有提到基于图像大小改变帧的内容。这很重要,因为我正在根据帧大小调整图像大小。
你必须给图像视图的宽度和高度约束,并将图像视图放置在uiview中,并给出前导和tralig以及顶部和底部的uiview约束 –