これがバグなのか、何か間違っているのかわかりません:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [self window];
UIViewController *main = [[UIViewController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] init];
UIViewController *vc2 = [[UIViewController alloc] init];
[main addChildViewController:vc1];
[main addChildViewController:vc2];
UIView *mainView = [main view];
UIView *v1 = [vc1 view];
UIView *v2 = [vc2 view];
[v1 setBackgroundColor:[UIColor redColor]];
[v2 setBackgroundColor:[UIColor blueColor]];
[v1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[v2 setTranslatesAutoresizingMaskIntoConstraints:NO];
[v1 setClipsToBounds:YES];
[v2 setClipsToBounds:YES];
[mainView setBackgroundColor:[UIColor yellowColor]];
[mainView addSubview:v1];
[mainView addSubview:v2];
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:v1
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual
toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0
constant:0.0];
[mainView addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:v1
attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual
toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0
constant:240.0];
[mainView addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:v2
attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual
toItem:v1 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[mainView addConstraint:constraint];
[window setRootViewController:main];
[window setBackgroundColor:[UIColor greenColor]];
[window makeKeyAndVisible];
[main release];
[vc1 release];
[vc2 release];
return YES;
}
v1
v2
アプリを起動してもどこにも表示されません。
私がコメントアウトした場合:
[v1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[v2 setTranslatesAutoresizingMaskIntoConstraints:NO];
自動サイズ変更マスクが制約に変換されたため、Cocoa は私の制約を満たすことができませんでした。