Make a small UIImageView easy to be tapped

249 views Asked by At

I have a UITableView with rows.
Each row has a small UIImageView aligned to the right (a "bookmark" icon)

The UIimageView has a UITapGestureRecognizer associated.

    cell.favoritedImageView.userInteractionEnabled = true
    cell.favoritedImageView.addGestureRecognizer(gestureRecognizer)

The problem is that to actually tap it with the finger (in a real device), you have to use the tip of the finger and be very accurate, because the image is small.

If you miss tapping the imageView, the cell is tapped (didSelectRowAtIndexPath) and you end up executing a show-segue to another view, so you have to go back and try again (not cool)

Question: what is the best way to solve this? I want it to be easy to be tapped.

I have some ideas:

  1. Create a larger image with transparent surrounding (ie: crop out with transparent background) -- downside is that I also use this image in other views, in which is not tappable, so I'd have to create two versions of the image
  2. Put the image inside a UIView and make the UIView big and tappable instead of the UIImageView
  3. Add padding to the UIImageView (will this work? or the padding is not recognized in the UITapGestureRecognizer?)
1

There are 1 answers

0
ngoue On

Per your own suggestion, you should create a transparent view that is much larger and attach the UITapGestureRecognizer to the view and then nest your smaller image within the view. That way appearances are the same, but you handle a much larger area for the tap to be recognized with selecting the cell.