Cho*_*pas 0 uitabbarcontroller uinavigationcontroller uiviewanimation ios
我正在尝试在触摸按钮时同时隐藏UITabBarController和UINavigationController.我在这里找到了一个非常好的代码片段如何隐藏uitabbarcontroller但是在尝试隐藏和动画UINavigationController和tabbarcontroller时我遇到了问题.我在互联网上发现了很多例子,当他们隐藏tabbar使用self.tabBarController.tabBar.hidden = YES但只隐藏按钮项而不是底部的黑条.
在玩了很多之后,我可以正确制作动画,因为我认为它与导航控制器的隐藏有关,这使得整个窗口的大小可以随时改变.
-(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)
{
}];
}
Run Code Online (Sandbox Code Playgroud)
}
hideTabBar和showTabBar方法是我上面链接的其他帖子中的方法.
我也试过其他一些组合,但我不能让它看起来不错.有任何想法吗?
提前致谢.
我现在尝试了这个代码,我发现UITabBar节目动画不能顺利进行.我设法通过调整显示动画的标签栏的持续时间来使其更平滑.
[UIView setAnimationDuration:0.2];
希望这有效.
编辑:请尝试此代码,它调整父视图的大小在1动画事务中更大,只有隐藏条和显示内容.
- (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;
}];
}
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
1305 次 |
| 最近记录: |