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