简体   繁体   English

点击时隐藏导航栏

[英]hide navbar when tapped

I am making a slideshow for in my app. 我正在我的应用程序中制作幻灯片。 I want it almost like the photo app of Apple. 我希望它几乎像Apple的照片应用程序。 It is almost finished just some small issues. 它几乎完成了一些小问题。 I want to hide the navbar when tapped on the screen and show it when tapped again. 我想在屏幕上点击时隐藏导航栏并在再次点击时显示它。 But I am not sure how to do this. 但我不知道该怎么做。

// catch the screen tap and call a method to hide the navigation bar
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleNavBar:)];
[self.view addGestureRecognizer:gesture];
[gesture release];

- (void)toggleNavBar:(UITapGestureRecognizer *)gesture {
    BOOL barsHidden = self.navigationController.navigationBar.hidden;
    [self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
}

How do you want to hide the navigation bar? 您要如何隐藏导航栏? Tapping in the navigation bar (which would be quite tricky, if not downright impossible) or via some other button or via another method? 导航栏中轻按(如果不是完全不可能的话,这将非常棘手)还是通过其他按钮或通过其他方法?

In general, you can definitely hide the navigation bar. 通常,您绝对可以隐藏导航栏。

Look at [UINavigationController setNavigationBarHidden: animated:] (I've linked the Apple documentation) 看看[UINavigationController setNavigationBarHidden: animated:] (我已经链接了Apple文档)

  1. Add Gesture to Screen using 使用将手势添加到屏幕

UITapGestureRecognizer *theSingleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self UITapGestureRecognizer * theSingleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self

action:@selector(handleSingleTapForImage:)]; 动作:@selector(handleSingleTapForImage :)]; [inImageView addGestureRecognizer:theSingleTapGesture]; [inImageView addGestureRecognizer:theSingleTapGesture]; [theSingleTapGesture release]; [theSingleTapGesture发布];

  1. In gesture method show or hide NavigationBar 在手势方法中显示或隐藏NavigationBar

     -(void)handleSingleTapForImage:(UITapGestureRecognizer *)sender { [self.navigationController setNavigationBarHidden:![self.navigationController isNavigationBarHidden] animated:YES]; 

    } }

使导航透明

self.navigationController.navigationBar.barStyle=UIBarStyleBlackTranslucent; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM