我有一个应用程序,其中有一个按钮可以使屏幕变黑。我也想让状态栏变黑,所以我使用以下代码:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
我可以设置淡入淡出的持续时间吗?如果这不可行,是否有可能获得官方的淡入淡出持续时间(如UIKeyboardAnimationDurationUserInfoKey
用于获取键盘滑动持续时间)。
好吧,我没有从任何人那里得到任何回报,但我认为我至少应该分享我的 hack。经过一些实验,我决定淡出是 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];
}];
}