我想要做的是首先隐藏导航栏,然后如果用户触摸屏幕顶部(它应该在的位置),导航栏将显示大约 1 秒或 2 秒然后消失。
我尝试添加一个与背景颜色相同的按钮,然后在触摸它时显示导航栏,但这似乎不起作用。
另外,我要如何做一个演示才能向用户展示这是可行的?谢谢!
最佳答案
首先在app delegate中隐藏导航栏,然后来到要添加触摸事件的view controller,使用这两个方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//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];
}
}
-(void)隐藏导航栏
{
self.navigationController.navigationBarHidden=YES;
if ([timer isValid]) {
[timer invalidate];
return;
}
关于ios - 如何在屏幕顶部附近显示带有触摸的导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10990963/