我正在构建基于文章的应用程序,我在我的应用程序中有标签栏和导航栏。我想要做的是当我点击该视图时我的文章正在显示,标签栏和导航栏应该隐藏,反之亦然。 请帮帮我
感谢您的回复,最后我使用了手势方法
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleTap)];
doubleTap.numberOfTapsRequired =1;
[scrollView addGestureRecognizer:doubleTap];
[doubleTap release]; - (void)handleDoubleTap {
NSLog(@"Single tap");
if(firstTime)
{
[UIView beginAnimations: @"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[self.navigationController setNavigationBarHidden:YES animated:YES];
scrollView.frame = CGRectMake(0,0,320,460.0f);
tabBar.hidden=YES;
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
firstTime=NO;
}
else {
[UIView beginAnimations: @"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
//[self.view bringSubviewToFront:scrollView];
[self.navigationController setNavigationBarHidden:NO animated:YES];
scrollView.frame = CGRectMake(0.0, 0.0, 320, 372);
tabBar.hidden=NO;
[UIView commitAnimations];
firstTime=YES;
}
现在,当我点击屏幕时,我得到了这个...当我滚动视图时可以隐藏标签栏和导航栏,反之亦然....请帮助我
答案 0 :(得分:1)
使用一个BOOL变量,我在.h文件中将其称为firstTime
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if(firstTime)
{
[self.navigationController hidesBottomBarWhenPushed];
firstTime=FALSE;
self.navigationController.navigationBar.hidden=TRUE;
}
else
{
[self.navigationController hidesBottomBarWhenPushed];
firstTime=TRUE;
self.navigationController.navigationBar.hidden=FALSE;
}
}
- (BOOL)hidesBottomBarWhenPushed
{
if(firstTime)
{
return TRUE;
}
else
{
return FALSE;
}
}
这会在单击时隐藏Tabbar和NavigationBar,反之亦然
答案 1 :(得分:0)
int DEF_BAR_HEIGHT = 40;
-(void)hideBars:(bool)value
{
// hide navigation bar
[self.navigationController setNavigationBarHidden:value animated:YES];
//hide tabBar
CGRect viewFrame = view.frame;
viewFrame.size.height += value ? DEF_BAR_HEIGHT : -DEF_BAR_HEIGHT; // Change this to the height of the tab bar
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
view.frame = viewFrame;
[UIView commitAnimations];
}
我不确定DEF_BAR_HEIGHT值。尝试40或40加导航栏高度。