【发布时间】:2010-01-23 18:25:09
【问题描述】:
我一直在寻找有关调整大小的背景信息,但找不到太多信息。我知道我需要在超级视图上设置autoresizesSubviews,在子视图上设置autoresizingMask。
我已经这样做了,我的 UIImageViews 正确调整大小,但我的自定义 UIView 子类没有。
UIImageView 的代码:
UIImageView *newX = [[[UIImageView alloc] initWithImage:dot] autorelease];
[newX setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[newX setFrame:CGRectMake(0, 0, self.view.bounds.size.width, 1)];
[self.view addSubview:newX];
自定义 UIView 子类的代码:
trace = [[TraceView alloc] initWithFrame:self.view.bounds];
[trace setAutoresizingMask:(UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin)];
[self.view addSubview:trace];
据我所知,视图按预期旋转,但没有调整大小。我再也看不到它的底部,它也没有填满右侧的屏幕。 是否必须向 UIView 子类添加任何内容才能正常调整大小?
编辑:
我已将 autoresizingMake 更改为 (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) 并调用 [subview setNeedsDisplay]; 我不确定为什么这是必要的,因为没有它 UIImageViews 可以正常工作,但它现在的行为符合预期。
【问题讨论】: