简体   繁体   English

如何以编程方式自动调整iPhone屏幕方向子视图的大小?

[英]How to autoresize the subviews for screen orientations in iPhone programmatically?

I have created a UIViewController class with a background color as red. 我创建了一个UIViewController类,其背景色为红色。 I have also created a UIView which is a subview and placed with a background image and two UIButtons on them. 我还创建了一个UIView,它是一个子视图,并放置了背景图像和两个UIButton。 The coding which i give for screen orientation is 我给出的屏幕方向编码是

 -(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;

Problem: 问题:

When i turn into Landscape the subview is resized with the image, but the buttons remain in the same position and i am not using any .xib file.I have created the project programmatically.Please do reply.... 当我变成风景时,子视图会随着图像调整大小,但是按钮保持在相同位置,并且我没有使用任何.xib文件。我已经以编程方式创建了该项目。请回复...。

Override layoutSubviews for your class. 覆盖类的layoutSubviews You might need to explicitly call [self setNeedsLayout] from didRotateFromInterfaceOrientation 您可能需要从didRotateFromInterfaceOrientation显式调用[self setNeedsLayout]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM