如何在屏幕顶部触摸显示导航栏?
我想要做的是首先隐藏导航条,然后如果用户触摸屏幕的顶部(应该在哪里),导航栏将显示大约1秒或2秒,然后消失。
我尝试添加一个与背景颜色相同的button,然后在触摸时显示导航栏,但这似乎不起作用。
另外我怎么做一个演示,所以我可以显示用户,这个工程? 谢谢!
首先隐藏应用程序委托中的导航栏,然后来到要添加触摸事件的视图控制器,并使用以下两个方法:
- (void)touchesBegan:(NSSet *)触及事件:(UIEvent *)事件
{
//mouseSwiped = NO; CGPoint touchPoint; //CGPoint touchPointNavigationBar; UITouch *touch = [touches anyObject]; touchPoint=[touch locationInView:self.view]; if (self.navigationController.navigationBarHidden==YES) { if (touchPoint.y<50) { self.navigationController.navigationBarHidden=NO; timer=[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(hideNavigationBar) userInfo:nil repeats:NO]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; } }
}
– (无效)hideNavigationBar
{
self.navigationController.navigationBarHidden=YES; if ([timer isValid]) { [timer invalidate]; return; }
}
这是获得输出的方法之一。 我正在逐行解释这个代码,这将会更好地帮助你。
1]
在你的视图的顶部添加一个button,并添加任何透明的背景图像到该button,然后写self.navigationController.navigationBarHidden = YES; 在viewDidLoad中。
//这将隐藏你的导航栏,现在你可以创build自己的导航栏。
2]
现在把xipa中的seviare UIView命名为view2,并连接到相应的IBOutlet。
采取相应的IBOutlets和IBAction和两个function,然后连接到查看和button。
下面的代码进入.h文件>>>>>
IBOutlet UIButton * btnHideNShow; //将它连接到button
IBOutlet UIView * viewTemp; //连接到View
– (IBAction为)btnHideNShowAction:(ID)发送者; / /连接到button
– (无效)FUN1;
– (无效)FUN2;
3]
现在下面的代码进入.m文件>>>>
– (IBAction为)btnHideNShowAction:(ID)发送方{
btnHideNShow.hidden = YES; [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fun1) userInfo:nil repeats:NO];
}
– (无效)FUN1 {
viewTemp.frame = CGRectMake(0, 0, 320, 59); [self.view addSubview:viewTemp]; [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fun2) userInfo:nil repeats:NO];
}
– (无效)FUN2 {
[viewTemp removeFromSuperview]; btnHideNShow.hidden = NO;
}
>您可以根据您的需求自定义此视图。