5
我發現了很多關於autoresizing的信息,但沒有一個能夠解決我的問題。我有一個視圖控制器(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];
}
出於某種原因,我不能當設備處於橫向模式時,獲取自動調整遮罩以調整按鈕寬度。任何幫助是極大的讚賞。
我相信你會需要設置autoresizingMask上的UIButton本身。 –
試過了。該按鈕最終被移出屏幕,這不是我所期望的,這意味着我不太瞭解它是如何工作的。也不是'self.autoresizesSubviews = YES;'的要點,所以我不必那樣做? –
您嘗試將按鈕autoresizeMask設置爲什麼?你有沒有嘗試過UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin? –