Navigation bar show/hide
This isn't something that can fit into a few lines of code, but this is one approach that might work for you.
To hide the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
To show it:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
Documentation for this method is available here.
To listen for a "double click" or double-tap, subclass UIView
and make an instance of that subclass your view controller's view
property.
In the view subclass, override its -touchesEnded:withEvent:
method and count how many touches you get in a duration of time, by measuring the time between two consecutive taps, perhaps with CACurrentMediaTime()
. Or test the result from [touch tapCount]
.
If you get two taps, your subclassed view issues an NSNotification
that your view controller has registered to listen for.
When your view controller hears the notification, it fires a selector that either hides or shows the navigation bar using the aforementioned code, depending on the navigation bar's current visible state, accessed through reading the navigation bar's isHidden
property.
EDIT
The part of my answer for handling tap events is probably useful back before iOS 3.1. The UIGestureRecognizer
class is probably a better approach for handling double-taps, these days.
EDIT 2
The Swift way to hide the navigation bar is:
navigationController?.setNavigationBarHidden(true, animated: true)
To show it:
navigationController?.setNavigationBarHidden(false, animated: true)
Make button show AND hide navigation on website?
You can just use .classList.toggle()
to toggle between css classes, notice that I removed the close function and open function, and moved the width to CSS class.
/*html, body {
max-width: 100%;
max-height: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
#fullbodybg{
position: absolute;
width: 170%;
height: 100%;
overflow: visible;
background: linear-gradient(
110deg,
#ffffff 50%,
#000000 50%);
outline: 5px dashed blue;
}*/
/* Header */
/* Style the header with a grey background and some padding */
.header {
overflow: hidden;
background-color: #FFFFFF;
padding-top: 40px;
padding-right: 10px;
padding-left: 10px;
padding-bottom: 50px;
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.2);
}
/* Style the header links */
.header a {
float: left;
color: black;
text-align: center;
padding-top: 12px;
padding-right: 12px;
padding-left: 12px;
padding-bottom: 12px;
text-decoration: none;
font-family: lato;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
.menu_bar_icon {
display: inline-block;
cursor: pointer;
position: relative;
z-index: 1;
}
.bar1, .bar2, .bar3 {
width: 20px;
height: 2px;
background-color: #000000;
margin: 4px 0;
transition: 0.4s;
}
/* Rotate first bar */
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-4px, 3px) ;
transform: rotate(-45deg) translate(-4px, 3px) ;
}
/* Fade out the second bar */
.change .bar2 {
opacity: 0;
}
/* Rotate last bar */
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-5px, -4px) ;
transform: rotate(45deg) translate(-5px, -4px) ;
}
/* The side navigation menu */
.sidenav {
height: 90px;
width: 352px;
position: fixed;
z-index: 1;
top: 0;
left: 70%;
overflow-x: hidden;
padding-top: 50px;
transition: 0.5s;
width: 500px;
right: -540px;
left: auto;
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 15px;
color: #000000;
display: block;
transition: 0.3s;
}
/* When you mouse over the navigation links, change their color */
.sidenav a:hover {
color: #E20105;
}
/* Position and style the close button (top right corner) */
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left .5s;
padding: 20px;
}
/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/* Style the logo link (notice that we set the same value of line-height and font-size to prevent the header to increase when the font gets bigger */
.header a.logo {
font-size: 130px;
font-weight: bold;
}
/* Change the background color on mouse-over */
.header a:hover {
background-color: #ddd;
color: black;
}
/* Style the active/current link*/
.header a.active {
background-color: dodgerblue;
color: white;
}
/* Float the link section to the right */
.header-right {
float: right;
}
/* Add media queries for responsiveness - when the screen is 500px wide or less, stack the links on top of each other */
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
#container{
width: 100%;/* Your width */
height: 100%;/* Your height */
display: flex;
justify-content: center; /* This will center container with items horizontally */
align-items: center; /* This will center container with items vertically */
/* outline: 5px dashed yellow;
*/
}
#mySidenav.open {
right: 0;
z-index: 0;
left: auto;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HFFoto - Portfolio</title>
<link rel="stylesheet" type="text/css" id="applicationStylesheet" href="portfolio_kunden.css"/>
<link href="http://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet" type="text/css">
<style type="text/css">
</style>
<script>
/*bar animation bar to cross*/
function myFunction(x) {
x.classList.toggle("change");
document.getElementById("mySidenav").classList.toggle('open');
}
</script>
</head>
<body>
<div class="header">
<a href="#default" class="logo">Kunden;</a>
<div class="header-right">
<div class="menu_bar_icon" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<div id="mySidenav" class="sidenav">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
</div>
Hide and show navigation bar for specific view without laggy animation
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
How to hide a navigation bar from first ViewController in Swift?
If you know that all other views should have the bar visible, you could use viewWillDisappear
to set it to visible again.
In Swift:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
Related Topics
Custom Class Clusters in Swift
Xcode UI Testing Error Keyboard
Xcode 10, Command Codesign Failed with a Nonzero Exit Code
Face Recognition on the Iphone
Connect Outlet of a Cell Prototype in a Storyboard
Cocoapods Could Not Find Compatible Versions for Pod "Firebase/Core" | Cloud_Firestore, Flutter
Show Current Location and Update Location in Mkmapview in Swift
How to Use Networkreachabilitymanager in Alamofire
Swift: Long Press Gesture Recognizer - Detect Taps and Long Press
App Getting Crash When Click on Googlesignin Button
How to Get the Incoming Call Number by Using Callkit
Datefromstring Returns Nil for Some Values
Development Team Not Showing in Xcode
Save and Retrieve Value via Keychain
How to Split String into Substrings on iOS