gpt4 book ai didi

ios - 使用动画隐藏 Navigation Controller 和 Tab Bar Controller

转载 作者:行者123 更新时间:2023-11-28 18:39:32 24 4
gpt4 key购买 nike

我试图在触摸按钮时同时隐藏 UITabBarController 和 UINavigationController。我在这里找到了一个非常好的代码片段 How to hide uitabbarcontroller但是我在尝试隐藏 UINavigationController 和 tabbarcontroller 并为其设置动画时遇到了问题。当他们使用 self.tabBarController.tabBar.hidden = YES 隐藏标签栏时,我还在互联网上发现了很多示例,但这只隐藏了按钮项而不是底部的黑条。

玩了很多次之后,我可以正确地制作两个动画,因为我认为这与导航 Controller 的隐藏有关,这使得整个窗口的大小可以动态改变。

-(IBAction)touchImage:(id)sender {

if (isImageFullScreen) {

isImageFullScreen = NO;

[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionCurveLinear
animations:^
{
hotelImageButton.frame = CGRectMake(0,20,320,92);
[self showTabBar:self.tabBarController];
}
completion:^(BOOL finished)
{
}];

} else {

isImageFullScreen = YES;

[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionCurveLinear
animations:^
{
hotelImageButton.frame = CGRectMake(0,0,320,480);
[self hideTabBar:self.tabBarController];
}
completion:^(BOOL finished)
{
}];
}

hideTabBar 和 showTabBar 方法来 self 上面链接的另一篇文章。

我也尝试了一些其他的组合,但我不能让它看起来很好。有什么想法吗?

提前致谢。

最佳答案

我现在尝试了该代码,发现 UITabBar 显示动画没有顺利进行。我通过将显示动画的标签栏的持续时间调整得更短,设法让它更流畅。

[UIView setAnimationDuration:0.2];

希望这能奏效。

编辑:请尝试此代码,它在 1 个动画事务中将父 View 的大小调整为更大,以便仅隐藏条形图并显示内容。

- (IBAction)TestButton1:(UIButton *)sender {

if(!isAnimating){
if(isTabBarAndNavBarHidden){

[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionNone
animations:^
{
isAnimating=YES;

CGFloat statusBar_height=[[UIApplication sharedApplication] statusBarFrame].size.height;
CGFloat screen_height=[UIScreen mainScreen].bounds.size.height;

[self.tabBarController.view setFrame:CGRectMake(self.tabBarController.view.frame.origin.x, 0, self.tabBarController.view.frame.size.width, screen_height)];
[self.navigationController.navigationBar setFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x, statusBar_height, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
}
completion:^(BOOL finished)
{
isTabBarAndNavBarHidden=NO;
isAnimating=NO;
}];

}else{

[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionNone
animations:^
{
isAnimating=YES;

CGFloat statusBar_height=[[UIApplication sharedApplication] statusBarFrame].size.height;
CGFloat screen_height=[UIScreen mainScreen].bounds.size.height;

[self.tabBarController.view setFrame:CGRectMake(self.tabBarController.view.frame.origin.x, statusBar_height-self.navigationController.navigationBar.frame.size.height, self.tabBarController.view.frame.size.width, screen_height+self.navigationController.navigationBar.frame.size.height+self.tabBarController.tabBar.frame.size.height-statusBar_height)];
[self.navigationController.navigationBar setFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height)];


}
completion:^(BOOL finished)
{
isTabBarAndNavBarHidden=YES;
isAnimating=NO;
}];

}
}

关于ios - 使用动画隐藏 Navigation Controller 和 Tab Bar Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13071767/

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