1

Is it possible to know if I successfully tapped on a SubView inside a UIView which is inside a UIScrollView during the hit test method?

UIScrollView->UIView->SubView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    // Do something
}

Thanks!

0xdeadfa11
  • 63
  • 1
  • 7

1 Answers1

0

A little more context would be good.

Your subview will will be the view handling the touch as long as it has userInteractionEnabled set to YES and is visible, i.e. not hidden and alpha greater than or equal to 0.01.

I'm not sure why you want to override hitTest:withEvent:, but if you're sure that's what you want to to do, then you should be able to solve your problem with pointInside:withEvent:.

Erik B
  • 40,889
  • 25
  • 119
  • 135
  • My `userInteractionEnabled` is already set to `YES`. What I want to do is to check if the user tapped on an `UIImageView` so I can stop the scrolling if possible. Thanks! – 0xdeadfa11 Jul 14 '12 at 02:32
  • Put your image view inside a UIButton or add a gesture recognizer to it – nielsbot Jul 14 '12 at 04:45
  • 1
    @0xdeadfa11 `UIImageView` has `userInteractionEnabled` set to `NO` by default. So forgetting to set `userInteractionEnabled` to `YES` for `UIImageView`s is a common mistake. Anyway, I think this answer will solve your problem: http://stackoverflow.com/a/4629821/310121 – Erik B Jul 14 '12 at 13:03
  • Yep, that would help but I have many `UIImageView`s and I want to work on a particular `UIImageView`. Lets say I solve the problem, the `UIScrollView` won't scroll now when tapped on the `UIImageView` but in some point I still want it to scroll (lets say the user holds his finger on the screen then swipes). And is it possible to know the direction of swipe on `hitTest:withEvent:`? Lets say, swiping diagonally upward will disable scrolling else the scroll is enabled. Thanks! – 0xdeadfa11 Jul 16 '12 at 02:30