gpt4 book ai didi

iphone - UIImageView autoresizingMask 行为

转载 作者:行者123 更新时间:2023-11-29 04:13:07 32 4
gpt4 key购买 nike

我有一个显示自定义单元格的 View 表格 View 。这些单元格有一个 UIImageView,如果设备处于横向模式,则需要对其进行缩放。

我将tableView的autoresizingMask设置为UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth,对我的自定义单元格和 UIImageView 执行了相同的操作。

我的问题是,为 UIImageView 设置 autoresizingMask 会更改 View 的框架,而无需对设备进行任何旋转。

这是我的 UIImageView 的初始化代码。

- (UIImageView *)bigImageView
{
if (!_bigImageView)
{
_bigImageView = [[UIImageView alloc] initWithFrame:(CGRect){2, [self.header getHeight], 272, 272}];
[_bigImageView setImage:[UIImage imageNamed:@"square.png"]];

[_bigImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

[_bigImageView setBackgroundColor:[UIColor redColor]];

}
return _bigImageView;
}

宽度应为272,但会自动更改为232

autoresizingMask 的预期结果应该是: TableView in blue, UIImageView in red

但我明白:

don't mind the shadow

该比例不再受到尊重。

最佳答案

发生这种情况是因为每个单元格的起始高度都是 44 点。你可以在 init 中检查一下。

也许您可以在 drawRect:layoutSubviews 中更正单元格元素的大小。

关于iphone - UIImageView autoresizingMask 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090522/

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