That below is part of my app when you click the screen it will register the touch and either move to the previous photo or the next photo depending on the touch . Right now anywhere that you touch the screen it will register and move to the previous or next image . I want to restrict that and only register touches on the red squares so that if you touch anything between the 2 red squares nothing will happen . This is my code
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self.view)
if location.x < self.view.layer.frame.size.width / 2 {
// touched left side of screen show previous image if exist
}
else {
// touched right side of screen show next
}
}
}
I think the key is the let location = touch.location(in: self.view) then location.x knows the width location where you touched . I want to only register taps on say the leftest 10% of the screen and the rightest 10% of the screen . Any suggestions would be great I'm using swift 4 .
( The red squares are only for illustration . I added using a photo editing feature it's not part of the app )
touchesBegan
is an unnecessarily involved process for this, and it may require overriding other touch methods depending on the subclass. – fake girlfriends