为什么隐藏我的状态栏会完全破坏我的简单动画?

示例项目: http //cl.ly/0O2t051o081p

我想实现一个滑出侧边栏,如本问题所述,状态栏也会移动。 我已经完成了所有工作并且侧边栏滑动,但是一旦我试图隐藏状态栏以完成“幻觉”,它就会阻止任何事情发生并且侧边栏不再滑出。

这是我的代码:

- (void)viewDidAppear:(BOOL)animated { double delayInSeconds = 1.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.PostsView addSubview:[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]]; hide = YES; [self setNeedsStatusBarAppearanceUpdate]; [UIView animateWithDuration:1.0 animations:^{ CGRect postsFrame = self.PostsView.frame; postsFrame.origin.x = self.MenuView.frame.size.width; self.PostsView.frame = postsFrame; }]; }); } 

我的代码基本上由一个包含视图控制器组成,其中包含两个构建在Storyboard中的子视图控制器(主视图控制器和侧边栏视图控制器)。

我也尝试在plist中将View controller-based status bar appearance设置为NO并调用[[UIApplication sharedApplication] setStatusBarHidden]但完全相同的结果发生在它中断的地方。

我究竟做错了什么?

我不确定为什么那条线会破坏你的动画,但如果我按照你在上一段中所说的那样做了,但是在动画之前在视图中添加了layoutIfNeeded(我确实将基于View控制器的状态栏外观设置为NO)在info.plist中)。

 - (void)viewDidAppear:(BOOL)animated { double delayInSeconds = 1.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.PostsView addSubview:[[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]]; [[UIApplication sharedApplication] setStatusBarHidden:YES]; [self.view layoutIfNeeded]; hide = YES; [UIView animateWithDuration:1.0 animations:^{ CGRect postsFrame = self.PostsView.frame; postsFrame.origin.x = self.MenuView.frame.size.width; self.PostsView.frame = postsFrame; }]; }); } 

此外,没有必要实现prefersStatusBarHidden。