我已经看到许多令人困惑的解决方案来处理iOS 7中的状态栏但是我喜欢Apple提到的解决方案 - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926
....但它不起作用!此方法按预期调用,但childView不向下移动20像素。
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
UIView *childView = self.childController.view;
id topGuide = self.topLayoutGuide;
CGFloat topBarOffset = self.topLayoutGuide.length; //I checked this valued is 20
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (childView, topGuide);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-20-[childView]"
options: 0
metrics: nil
views: viewsDictionary
]
];
}
}
以下为我工作,但我真的想使用topLayoutGuide使用AutoLayout来解决这个问题。
- (void)layoutSubviews
{
[super layoutSubviews];
self.backgroundColor = [UIColor blackColor];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect frame = self.bounds;
frame.origin.y = 20;
frame.size.height -= 20;
self.childView.frame = frame;
} else {
self.childView.frame = self.bounds;
}
}
为什么使用topLayoutGuide无法正常工作?感谢。