12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NavigationBarとStatusBarを同時に消す

Last updated at Posted at 2012-08-29
- (void)setBarHidden:(BOOL)hidden animated:(BOOL)animated
{
  NSTimeInterval duration = 0.0;
  if (animated) {
    duration = 0.3;
  }
 
  // 先にStatusBarの表示を始める
  [[UIApplication sharedApplication] setStatusBarHidden:hidden withAnimation:UIStatusBarAnimationFade];
  
  // 表示する場合、実際は先に表示設定にする
  if (!hidden) {
    [self.navigationController setNavigationBarHidden:NO];
  }
  
  [UIView animateWithDuration:duration animations:^{
    self.navigationController.navigationBar.alpha = hidden ? 0 : 1;
  } completion:^(BOOL finished) {
    // 非表示にする場合、アニメーション終了後、非表示設定にする
    if (hidden) {
      [self.navigationController setNavigationBarHidden:YES];
    }
  }];
}

追記:StatusBarが既に消えている場合、NavigationBarの位置がずれる問題に対処

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?