1

I have looked at similar posts here about gesture recognizers not working and I have tried all of their solutions to no avail. I have created dozens of gesture recognizers in the past and its been a few hours that I can't get this one to work and I'm ready to drown myself.

Here are my 3 Horizontal stacks I have in a view: https://i.stack.imgur.com/Sj9mi.jpg

I have added a gesture recognizer to a horizontal stack like so:

menuView.addSubview(Hstack1)
Hstack1.anchor(top: nil, left: menuView.leftAnchor, bottom: nil, right: menuView.rightAnchor, paddingTop: 0, paddingLeft: 15, paddingBottom: 0, paddingRight: 15, width: menuView.frame.width, height: 30)
Hstack1.topAnchor.constraint(equalTo: menuView.topAnchor, constant: 100).isActive = true
var tap = UITapGestureRecognizer(target: self, action: #selector(openProfileController))
Hstack1.addGestureRecognizer(tap)

My function that should be triggered:

@objc func openProfileController() {
    navigationController?.pushViewController(ProfileController(), animated: true)
}

I even tried making "Profile" a button with an action method but that didn't work. I also tried adding a gesture to the whole black menu view but nothing was triggered.

Edit: I have been playing around with the view for hours and I have learned that it has something to do with the menu views frame. In order to get the slide menu, I shift my view controller in an animation like this:

self.view.frame.origin.x = self.view.frame.origin.x + 250

The menu's frame is initially:

menuView.frame = CGRect(x: -250,y: 0, width: 250, height: view.frame.height)

But since it is a subview of the view controller, it shifts also 250 to the right. Visually, this is exactly what I want. However, it seems that the menuView's frame is not updated during this animation and continues to be at -250, 0.

Any ideas on how to fix this?

  • `isUserInteractionEnabled` is true for your stack? – inokey Apr 08 '20 at 06:24
  • yes it is enabled – Ludovico Verniani Apr 08 '20 at 06:53
  • Ok, did you try to inspect the interface in runtime? Is the frame of the view that contains stacks is properly set? The only guess I have is that the actual frame is somehow zero size and in that case your taps are missing is because they don't land in the view itself. – inokey Apr 08 '20 at 07:02
  • On a side note: did you check that openProfileController is not triggered? Or it is triggered but navigation is not happening? – inokey Apr 08 '20 at 07:03
  • I did inspect at runtime, just added a pic https://imgur.com/a/HKIaNRV. The view that the stacks are in seem to be framed properly. I have a print statement in my selector but nothing is printing. – Ludovico Verniani Apr 08 '20 at 07:23
  • Its strange because buttons and gesture recognizers in the menu view all don't trigger their corresponding selectors. – Ludovico Verniani Apr 08 '20 at 07:25
  • Could it be that the ViewController on the right (the white one) is in the view hierarchy so that it catches all the gestures. So it's frame is not moving when you showing the side menu? Check that with hit test. – inokey Apr 08 '20 at 07:27
  • added another picture to help you visualize the hierarchy https://imgur.com/a/HKIaNRV I just looked up what a hit test is, for a signature like this: https://www.reddit.com/r/iOSProgramming/comments/9nzvkj/pointinsidewith_vs_hittest_with_want_to/ what should I pass in to the hitTest function? – Ludovico Verniani Apr 08 '20 at 07:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/211191/discussion-between-ludovico-verniani-and-inokey). – Ludovico Verniani Apr 08 '20 at 08:32
  • With your latest edits: check the bounds of the menu view not the frame. https://stackoverflow.com/questions/1210047/cocoa-whats-the-difference-between-the-frame-and-the-bounds – inokey Apr 08 '20 at 19:04

0 Answers0