我创建了一个简单的 iOS 应用程序,该应用程序创建了一个 UIViewController,其中包含一个 View。这是应用程序委托:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
这是 UIViewController 中的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"breakpoint here");
}
我在“断点”行上放了一个断点。运行应用程序并在进入调试器后输入以下内容:
(lldb) po [[UIWindow keyWindow] _autolayoutTrace]
$0 = 0x0a056d30
*<UIWindow:0x8078de0>
| *<UIView:0xa053fe0>
这是该 UIView 的水平约束:
(lldb) po [0xa053fe0 constraintsAffectingLayoutForAxis:0]
$1 = 0x0a05ba60 <__NSArrayM 0xa05ba60>(
<NSLayoutConstraint:0xa059560 H:|-(0)-[UIView:0xa053fe0](LTR) (Names: '|':UIWindow:0x8078de0 )>,
<NSLayoutConstraint:0xa0595e0 UIView:0xa053fe0.right == UIWindow:0x8078de0.right>,
<NSAutoresizingMaskLayoutConstraint:0x8571520 h=--- v=--- H:[UIWindow:0x8078de0(768)]>
)
所以这是一个简单的问题,所以我理解得更好。如果自动布局应该是新的东西,而不是自动调整掩码,为什么 UIWindow 强制使用 NSAutoresizingMaskLayoutConstraint?我应该使用不同的初始化程序来使 UIWindow 使用常规约束吗?也许我的 UIWindow 上的 initWithFrame 是罪魁祸首?
谢谢!