uchicago-mobi / MPCS51030-2017-Winter-Forum

7 stars 0 forks source link

Gesture Recognizer #85

Closed turabhassan89 closed 7 years ago

turabhassan89 commented 7 years ago

I have setup the gesture reconizer for both circle and cross but it seems to be only working for the circle and I cant figure out why.

tabinks commented 7 years ago

Conceptually, they should work the same...so it's a bug somewhere.

Some things to look at:

turabhassan89 commented 7 years ago

I was making one gesture recognizer and then attaching it to both the circle and cross imageviews and it was working only for one. I had to make two separate ones, conceptually what is happening?

This doesnt work: let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) cross.addGestureRecognizer(panGesture) circle.addGestureRecognizer(panGesture) This works: let panCircleGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) let panCrossGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) cross.addGestureRecognizer(panCircleGesture) circle.addGestureRecognizer(panCrossGesture)

susanstevens commented 7 years ago

Each gesture recognizer can only be hooked up to one view. When you add the same gesture recognizer to two views, it will be removed from the first view when you add it to the second.

Think about why it would be confusing for the system to apply the same gesture recognizer to multiple views. What would happen when you accessed 'recognizer.view'?