自动调整掩码如何工作?

我发现了很多关于自动调整的信息,但是没有一个能够解决我的问题。 我有一个ViewController(RAViewController)在其loadView方法中调用视图,如下所示:

- (void)loadView { // Set Navigation Bar Title self.navigationItem.title = @"RA"; // Add Background view self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Add RAView RAView *rAView = [[RAView alloc] initWithFrame:self.view.frame Controller:self]; [self.view rAView]; } 

它调用的视图(RAView)如下所示:

 - (id)initWithFrame:(CGRect)frame Controller:(RAViewController *)Controller { self = [super initWithFrame:frame]; if (self) { // Initialization code self.autoresizesSubviews = YES; self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; controller = Controller; // Draw Architecture View [self drawArchitectureView]; } return self; } -(void)drawArchitectureView { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50); [button setBackgroundColor:[UIColor grayColor]]; [button setTitle:@"Overview" forState:UIControlStateNormal]; [self addSubview:button]; } 

出于某种原因,我无法使用自动resize的掩码来调整设备处于横向时的button宽度。 任何帮助是极大的赞赏。

如果你想保持同样的高度,但保持完全居中,10.0左右,请尝试:

 -(void)drawArchitectureView { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50); button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin; [button setBackgroundColor:[UIColor grayColor]]; [button setTitle:@"Overview" forState:UIControlStateNormal]; [self addSubview:button]; }