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:UIViewAutoresizingFlexibleWidth];
[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
UIViewAutoresizingFlexibleHeightor width on the subview. Otherwise I think the view just moves around according to the margins but doesn’t resize.