gpt4 book ai didi

ios - 默认 iOS UINavigationBar 动画不流畅

转载 作者:行者123 更新时间:2023-11-29 04:41:05 25 4
gpt4 key购买 nike

我正在开发一个应用程序,需要隐藏 UINavigationBar(和工具栏)以在应用内浏览器中提供全屏模式。

当应用程序运行此代码时,动画工作正常。

[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];

当我想退出全屏模式时,动画一点也不流畅。

[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController setToolbarHidden:NO animated:YES];

在动画过程中,导航栏下方可见一个黑色矩形,我认为是 UIWebView 自行调整了大小(工具栏动画效果很好。)

知道如何解决这个问题吗?

最佳答案

不要使用 setNavigationBarHidden:animated: 来隐藏导航栏,而是尝试以下操作:

在 View Controller 的 viewDidLoad 中为导航栏和 View 计算不同的框架:

// The normal navigation bar frame, i.e. fully visible
normalNavBarFrame = self.navigationController.navigationBar.frame;

// The frame of the hidden navigation bar (moved up by its height)
hiddenNavBarFrame = normalNavBarFrame;
hiddenNavBarFrame.origin.y -= CGRectGetHeight(normalNavBarFrame);

// The frame of your view as specified in the nib file
normalViewFrame = self.view.frame;

// The frame of your view moved up by the height of the navigation bar
// and increased in height by the same amount
fullViewFrame = normalViewFrame;
fullViewFrame.origin.y -= CGRectGetHeight(normalNavBarFrame);
fullViewFrame.size.height += CGRectGetHeight(normalNavBarFrame);

当您想要全屏时:

[UIView animateWithDuration:0.3
animations:^{
self.navigationController.navigationBar.frame = hiddenNavBarFrame;
self.view.frame = fullViewFrame;
} completion:^(BOOL finished) {

}];

当您想恢复正常时:

[UIView animateWithDuration:0.3
animations:^{
self.navigationController.navigationBar.frame = normalNavBarFrame;
self.view.frame = normalViewFrame;
} completion:^(BOOL finished) {

}];

在 iOS 5.1 模拟器中对此进行了测试。希望你能用它。 “黑色矩形”必须是窗口的默认背景颜色,即导航栏和 View 之间的间隙。

关于ios - 默认 iOS UINavigationBar 动画不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10383916/

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