2012-06-21 56 views
4

我有一個應用程序,我有一個按鈕將屏幕淡化爲黑色。我想有狀態欄黑漸變也是,所以我用下面的代碼:UIStatusBarAnimationFade持續時間

[[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]; 
    }]; 
} 

回答

0

我有同樣的問題,我的值是0.5隱藏和0.2顯示與狀態欄在一起的導航欄。至少在iOS 6.1/iOS模擬器中,這些值與現實相比要好得多。