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 の使用が機能しない理由はありますか? ありがとう。