UIImageView 忽略 contentMode 的变化
我对这个尺寸错误感到非常困惑。我的视图布局中有一个 UIImageView 和一个 UITableView 。 UIImageView 在 IB 中设置为 Aspect Fit,当我使用 IB 设置图像时,它的行为就像我想要的那样。但是当我以编程方式设置图像时,它会错误地调整视图大小。
我已经尝试了所有我能想到的方法来让它在模拟器中正确显示,但没有任何结果。
bannerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
bannerView.image = banner;
bannerView.frame = CGRectMake(0,0,320,80);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
self.tableView.frame = CGRectMake(0,80,320,380);
现在真正有趣的是,即使我构建框架的方式,此代码中的表格视图也应该位于图像视图的正下方。事实上,事实并非如此。表格视图不会从我将其放置在 IB 中的位置移动(具有精确的帧大小和坐标),但图像视图由于某种原因要小得多。
请帮忙,这对我来说没有任何意义为什么这不起作用
I'm absolutely stumped with this sizing bug I have. I have a UIImageView and a UITableView in my view layout. The UIImageView is set to Aspect Fit in IB, and it behaves as I want it to when i set the image using IB. but when I set the image programmatically, it resizes the view incorrectly.
I've tried everything I can think of to get this to appear correctly in the simulator and nothing comes out right.
bannerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
bannerView.image = banner;
bannerView.frame = CGRectMake(0,0,320,80);
bannerView.contentMode = UIViewContentModeScaleAspectFit;
self.tableView.frame = CGRectMake(0,80,320,380);
Now the really interesting thing is that even though by the way I am constructing their frames, the tableview in this code should be directly below the image view. In reality, it is not. The table view doesnt move from where I had placed it in IB (with that exact frame size and coordinates), but the image view is way smaller for some reason.
Pleas help, this doesn't make any sense to me why this doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,问题似乎出在 IB 中,我在视图的自动调整大小部分中检查了所有箭头,而我只需要检查顶部和左侧的箭头以保持对齐
Ok, it seems the problem was in IB I had in the autosizing section for the view, all of the arrows were checked, when I only needed the top and left ones checked to keep it aligned