0

我创建了一个背景颜色为红色的 UIViewController 类。我还创建了一个 UIView,它是一个子视图,并在其上放置了一个背景图像和两个 UIButton。我为屏幕方向提供的编码是

 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

self.view =[[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.view.backgroundcolor =[UIColor redColor];
UIView *subview;
subview = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@""]];
subview.autoresizingMask = UIViewAutoResizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;

问题:

当我变成横向时,子视图会随图像调整大小,但按钮保持在同一位置,我没有使用任何 .xib 文件。我已经以编程方式创建了项目。请回复....

4

1 回答 1

0

覆盖layoutSubviews您的课程。您可能需要显式调用[self setNeedsLayout]from didRotateFromInterfaceOrientation

于 2010-05-19T11:43:02.397 回答