2

I have two draggable elements on screen, tableview A and imageview B. A is above B in the hierarchy and must always remain so. The diagram below outlines the issue.

gestures on layers http://www.kettleholdings.com/gestures.jpg

Before I start coding this, is the above a viable and credible solution to this or is there some kind of clever priority setting that will always trigger the B gesture if the interaction is located over both A and B?

Thanks

Wain
  • 118,658
  • 15
  • 128
  • 151
RobertyBob
  • 803
  • 1
  • 8
  • 20
  • http://stackoverflow.com/questions/3834301/ios-forward-all-touches-through-a-view – Dare Apr 20 '16 at 14:10
  • Where are your gestures configured? In each view separately or in the main view? I suggest you this last option so you'll have the same action for the gestures in both views. Therefore, when accessing the method being called by the gesture, you can access to the touched point: CGPoint touchPoint = [gestureRecognizer locationInView:self.view]; After that you can try [imageViewB pointInside:touchPoint withEvent:nil]; to check whether the imageview B contains that touch point. If it's true, then move that view instead of A. – Leandro Fournier Apr 20 '16 at 14:18
  • Thanks guys - the references to pointInside have given me a decent starting point for sorting this out. Can I confirm that I add the gesture to the main view, then when gesture is called I check what elements contain the point touched and decide which of them gets assigned the action? – RobertyBob Apr 20 '16 at 14:27
  • This works great - pointInside was the clue though I used CGRectContainsPoint() for Swift 2.0 – RobertyBob Apr 21 '16 at 10:01

1 Answers1

0

To clarify, the duplicate answer helped me to find a solution as follows.

Put the gestures on the main view then within the gesture recogniser process determine what objects are located where the gesture was performed and whether to have the gesture do anything.

func doLongPressGesture(sender: UILongPressGestureRecognizer) {    
    let touchLocation = sender.locationInView(self.view)
    if CGRectContainsPoint(myChosenObject.frame, touchLocation) {
        ....
    }
}
RobertyBob
  • 803
  • 1
  • 8
  • 20