【发布时间】:2017-12-14 01:45:22
【问题描述】:
我不知道为什么我以编程方式创建的约束是模棱两可的,我什至尝试从具有相同约束的 Nib 初始化,它可以工作,但为什么我的代码不是。
@interface rootViewController: UIViewController
@end
@implementation rootViewController
- (void)loadView
{
self.view = [[UIView alloc] init];
UIView *theView = [[UIView alloc] init];
[self.view addSubview:theView];
NSArray *arr = @[
[theView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
[theView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
[theView.centerXAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.centerXAnchor],
[theView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor]];
[NSLayoutConstraint activateConstraints:arr];
}
@end
//And I load it in the ApplicationDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] init];
self.window.rootViewController = [[rootViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
调试时找不到问题真的很有趣。
【问题讨论】:
标签: ios iphone autolayout