为什么隐藏我的状态栏会完全破坏我的简单动画? [英] Why does hiding my status bar completely break my simple animation?
问题描述
示例项目: http://cl.ly/0O2t051o081p
我想实现一个滑出侧边栏,如这个问题,状态栏也会移动。我已经完成了所有工作并且侧边栏滑动,但是一旦我试图隐藏状态栏以完成幻觉,它就会阻止任何事情发生并且侧边栏不再滑出。
I want to achieve a slide-out sidebar as described in this question where the status bar moves as well. I've got everything working and the sidebar slides, but as soon as I try to hide the status bar with to complete the "illusion" it stops anything from happening at all and the sidebar no longer slides out.
这是我的代码:
- (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;
}];
});
}
我的代码基本上包含一个包含两个子视图控制器的包含视图控制器(主视图控制器和侧边栏视图控制器)内置在故事板中。
Where my code basically consists of a containing view controller that contains two child view controllers (the main view controller and the sidebar view controller) built in the Storyboard.
我还尝试设置查看基于控制器的状态栏外观
在plist中 NO
并调用 [[UIApplication sharedApplication] setStatusBarHidden]
但确切同样的结果发生在它破裂的地方。
I've also tried setting View controller-based status bar appearance
in the plist to NO
and calling [[UIApplication sharedApplication] setStatusBarHidden]
but the exact same result happens where it breaks.
我做错了什么?
推荐答案
我不确定为什么那条线会破坏你的动画,但是如果我按照你在上一段中所说的那样做了它,但在动画之前在视图中添加了layoutIfNeeded(我确实设置了基于View控制器的状态栏)在info.plist中显示为NO。。
I'm not sure why that line breaks you animation, but it worked properly if I did what you said in your last paragraph, but added a layoutIfNeeded to the view before the animation (I did set View controller-based status bar appearance to NO in the 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。
Also it's unnecessary to implement prefersStatusBarHidden.
这篇关于为什么隐藏我的状态栏会完全破坏我的简单动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!