15

オートレイアウトとインコールステータスバーについてお聞きしたいです。私の問題を示す簡単なシナリオは次のとおりです。

  1. 「ストーリーボードを使用」を有効にしてプロジェクトを作成する
  2. 「View Controller」を追加し、その「Is Initial View Controller」を有効にします
  3. コントローラーのビューの背景色を赤に設定
  4. コントローラーのビューに「テーブル ビュー」を追加します。

テーブル ビューには、Superview に対する 4 つのレイアウト制約 (前、上、後、下) があり、定数が 0 に設定されている必要があります。

このアプリをシミュレーターで実行して押すと⌘</kbd> + T I can see red background while the in-call status bar animates in. Is it possible to get rid of this glitch?

4

3 に答える 3

7

純粋に自動レイアウトの回答の場合、下の制約への参照を取得し、UIApplicationWillChangeStatusBarFrameNotification を受信したときにその定数を調整し、DidChange 通知を受信したときに 0 に戻すことができます。使用したテスト VC は次のとおりです。

@interface CEViewController ()

@property (nonatomic, strong) IBOutlet NSLayoutConstraint *bottomConstraint;

@end

@implementation CEViewController

- (void)viewDidLoad {
    [super viewDidLoad];        

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameDidChange:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

- (void)statusBarFrameWillChange:(NSNotification *)note {
    NSValue *newFrameValue = [note userInfo][UIApplicationStatusBarFrameUserInfoKey];

    self.bottomConstraint.constant = newFrameValue.CGRectValue.size.height;
    [self.view setNeedsLayout];
}

- (void)statusBarFrameDidChange:(NSNotification *)note {
    self.bottomConstraint.constant = 0;
    [self.view setNeedsLayout];
}

@end
于 2013-05-14T15:38:08.357 に答える
2

これは、画面のサイズ変更による効果です。

通話中のステータス バーが表示されると、通話中のステータス バーがアクティブな状態でビューのサイズが変更され、ステータス バーのサイズが変わるとビューが下に移動します。

しばらくの間、テーブル ビューの下のビューが表示されます。あなたができることは、テーブルビューの下にビューを追加して、画面から下に伸びて背景色を隠すことです。

別のアプローチは、あなたAppDelegateの実装です:

-application:willChangeStatusBarFrame:

テーブルビューのサイズを変更して、露出するビットをカバーします。次に、 -application:didChangeStatusBarFrame:が呼び出されたら、サイズを変更して元のサイズに戻します。

于 2013-05-08T12:33:18.520 に答える