开发者

UIView subclass won't autoresize

I've been looking for background information on resizing, but I haven't been able to find much. I know I need to set autoresizesSubviews on the superview and autoresizingMask on the subview.

I have done this, and my UIImageViews properly resize, but my custom UIView subclass does not.

The code for the UIImageView:

UIImageView *newX = [[[UIImageView alloc] initWithImage:dot] autorelease];
[newX setAutoresizingMask:UIViewAutoresi开发者_StackOverflow社区zingFlexibleWidth];
[newX setFrame:CGRectMake(0, 0, self.view.bounds.size.width, 1)];
[self.view addSubview:newX];

The code for the custom UIView subclass:

trace = [[TraceView alloc] initWithFrame:self.view.bounds];
[trace setAutoresizingMask:(UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin)];
[self.view addSubview:trace];

From what I can tell, the view rotates as expected, but does not resize. I can no longer see the bottom of it, and it doesn't fill the screen to the right. Do I have to add anything to the UIView subclass to make resizing work properly?

EDIT: I've changed the autoresizingMake to (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) and called [subview setNeedsDisplay]; I'm not sure why this is necessary as the UIImageViews work fine without it, but it now behaves as expected.


I think you're missing UIViewAutoresizingFlexibleHeight or width on the subview. Otherwise I think the view just moves around according to the margins but doesn't resize.


You mention rotation. Is the superview that contains your custom view actually resizing correctly? If in doubt, set its background to some odd color. If it did not resize correctly after the orientation change then you should see a white or grey bar on the right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜