0

I found that touchDown event is kind of slow, in that it requires a major, fairly long touch and does not respond to a light tap. Why is that?

Whereas, touchesBegan responds just when I need it to, i.e. responds even to very light, quick touches. But that's not an event but a method that can be overridden.

Problem is, touchesBegan apparently requires me to either 1) subclass a label (I need to respond to touching a label), or 2) analyze the event to figure out whether it came from the right label. I am wondering whether it's a code smell and whether there should be an event for simple touch.

Irina Rapoport
  • 1,404
  • 1
  • 20
  • 37
  • Can you please explain what you want to achieve? Because your request is quite confusing. – doruvil Apr 19 '16 at 07:47
  • If you want to add a tap gesture recognizer to a UILabel check this: http://stackoverflow.com/questions/10079019/how-can-i-add-a-uitapgesturerecognizer-to-a-uilabel-inside-a-table-view-cell maybe a duplicate – doruvil Apr 19 '16 at 07:49

3 Answers3

1

Try to add a UITapGestureRecognizer to your label.

Vahan Babayan
  • 723
  • 7
  • 21
0

First of all, allow label to handle user interaction:

label.userInteractionEnabled = true

You can assign tap gesture to label. Then in handler method you need to switch over state property of recognizer. If it is .Began, you got the event that you need.

The cool thing about this approach that you could use this one handler for all of your labels. Inside handler, you can get touched label like this:

let label = tapRecognizer.view as! UILabel
Alexander Doloz
  • 4,078
  • 1
  • 20
  • 36
-1

"Code smell"? No, it's a user interface smell. A user interface stink.

If you make a button in your user interface behave different from buttons in any other application, people will hate your app. Do what people are used to.

gnasher729
  • 51,477
  • 5
  • 75
  • 98