自動化マスクはどのように機能しますか?
-
28-10-2019 - |
質問
自動化に関する多くの情報を見つけましたが、私の問題を解決することはできませんでした。 viewcontroller(raviewcontroller)があります。
- (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];
}
何らかの理由で、デバイスがランドスケープであるときにボタン幅をサイズ変更するために自動化マスクを取得できません。どんな助けも大歓迎です。
解決
同じ高さを維持したいが、左右から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];
}
所属していません StackOverflow