I have these buttons on my cameraView that I want to hide when pressing on the view. I got that to work but I want to unhide the buttons when I press on the view again. How would I be able to do that?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if touch?.view == self.cameraView {
flipCamera.isHidden = true
lockButton.isHidden = true
print("Hide buttons")
} else if touch?.view == self.cameraView && flipCamera.isHidden == true {
print("show buttons")
}
If you want to change the
isHiddenvalue to its opposite on each touch, you can simply use thetoggle()function, which toggles aBoolvalue - it assignsfalseif the value wastrueand assignstrueif the value wasfalse.