UIStatusBarAnimationFade持续时间

时间:2012-06-21 14:58:54

标签: objective-c ios cocoa-touch uistatusbar

我有一个应用程序,我有一个按钮,将屏幕淡化为黑色。我想让状态栏淡出为黑色,所以我使用以下代码:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

我可以设置淡入淡出的持续时间吗?如果这不可行,是否可以获得正式的淡入淡出持续时间(例如使用UIKeyboardAnimationDurationUserInfoKey来获得键盘滑动持续时间)。


我没有从任何人那里得到任何回报,但我认为我至少应该分享我的黑客。经过一些实验,我决定淡出为1秒,淡入为0.25秒。

- (IBAction)fadeToBlack:(id)sender
{
    UIView *view = [[[UIView alloc] initWithFrame:self.view.window.frame] autorelease];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.0;
    [self.view.window addSubview:view];

    // NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
    [UIView animateWithDuration:1.0 animations:^{
        view.alpha = 1.0;
    } completion:^(BOOL finished) {
        [view addGestureRecognizer:self.dismissViewGesture];
    }];
}

- (void)dismissViewWithGesture:(UIGestureRecognizer *)gesture
{
    UIView *view = gesture.view;
    [view removeGestureRecognizer:gesture];

    // NOTE: Fading the black view at the same rate as the status bar. Duration is just a guess.
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    [UIView animateWithDuration:0.25 animations:^{
        view.alpha = 0.0;
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
    }];
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,隐藏的值为0.5,显示导航栏和状态栏的值为0.2。 至少对于iOS 6.1 / iOS模拟器,这些值与现实相匹配得更好。