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