gpt4 book ai didi

iphone - 同时隐藏状态栏和导航栏,就像在图片应用程序中一样

转载 作者:可可西里 更新时间:2023-11-01 03:49:34 26 4
gpt4 key购买 nike

我有一个包含很多文本的 View ,所以我想允许用户在单击时隐藏 statusBar+navigationBar。我真的很喜欢 Pictures 应用程序中的隐藏样式,其中 statusBar 和 navigationBar 隐藏在一起(不滑动,只是淡出),带有一些 animationDuration,所以我尝试做类似的事情。这是我在 touchesDidBegan 方法中所做的:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UIView setAnimationDuration:0.5];
[UIView beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationNone];
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:NO];
[UIView commitAnimations];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}

但这不会同时隐藏栏。它使它们滑落。它与上述方法的此版本具有相同的效果:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
// deleted UIView animation, changed animation type to "slide"
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:UIStatusBarAnimationSlide];
// enabled animation for navBar
[self.navigationController setNavigationBarHidden:(!self.navigationController.navigationBarHidden) animated:YES];
self.navigationController.navigationBar.translucent = !self.navigationController.navigationBar.translucent; // this is needed to make bars appear on top of my view.
}

如果我摆脱 UIView 动画并隐藏没有动画的栏,它们确实会同时隐藏和出现,但速度太快了。也许我走错了方向。如果有人能帮我解决这个问题,我将不胜感激。

编辑:开始工作

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// don't forget to set navigationBar.translucent to YES
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
[UINavigationBar setAnimationDuration:3.0];

[UINavigationBar beginAnimations:@"" context:nil];
[[UIApplication sharedApplication] setStatusBarHidden:!([UIApplication sharedApplication].statusBarHidden) withAnimation:NO];
if ([UIApplication sharedApplication].isStatusBarHidden)
[self.navigationController.navigationBar setAlpha:0.0];
else [self.navigationController.navigationBar setAlpha:1.0];
[UINavigationBar commitAnimations];
}

最佳答案

隐藏 UIStatusBar 动画:

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

隐藏 UINavigationBar 动画:

[UINavigationBar beginAnimations:@"NavBarFade" context:nil];
self.navigationController.navigationBar.alpha = 1;
[self.navigationController setNavigationBarHidden:YES animated:NO]; //Animated must be NO!
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UINavigationBar setAnimationDuration:1.5];
self.navigationController.navigationBar.alpha = 0;
[UINavigationBar commitAnimations];

关于iphone - 同时隐藏状态栏和导航栏,就像在图片应用程序中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15215920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com