【发布时间】:2013-12-17 06:16:28
【问题描述】:
我正在尝试(正在努力)在 iOS7 中为我的应用程序实现类似 snapchat 的错误消息显示(snapchat 错误消息以某种方式滑过状态栏)。我一辈子都无法让我的动画正常工作。这是我制作动画的方法
- (void)animateHeaderViewWithText:(NSString *)text {
//add header views
[self.headerView addSubview:self.headerLabel];
[self.navigationController.view addSubview:self.headerView];
//Hide the Status Bar
statusBarHidden = TRUE;
[self setNeedsStatusBarAppearanceUpdate];
self.headerLabel.text = text;
[UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.headerLabel.frame = CGRectMake(0, 0, 320, 20);
self.headerView.frame = CGRectMake(0, 0, 320, 20);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.5 delay:5.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//UnHide the Status Bar
statusBarHidden = FALSE;
[self setNeedsStatusBarAppearanceUpdate];
self.headerLabel.frame = CGRectMake(0, -20, 320, 20);
self.headerView.frame = CGRectMake(0, -20, 320, 20);
} completion:^(BOOL finished) {
[self.headerView removeFromSuperview];
[self.headerLabel removeFromSuperview];
}];
}];
}
只有动画的后半部分真正正常工作,消息滑回正常,状态栏出现在其下方。然而,动画的前半部分,当视图向下滑动时,状态栏消失导致我的导航栏向上移动,搞砸了我的动画。如何让我的导航栏保持在最初放置的位置,即使状态栏消失了
【问题讨论】:
-
调用
setNeedsStatusBarAppearanceUpdate方法会导致重绘视图并将导航栏移到顶部。在不这样做的情况下找到解决方法。 -
你需要这个同时在纵向和横向上工作吗?
-
只有肖像@rdelmar
标签: ios objective-c xcode animation statusbar