Slide over UIViews To Select

I have a bar graph which I’ve created. Each bar is a UIView. You can tap on each bar and it’ll display its value in a label above. How make it so that you could just slide/pan over the bars and it would select whichever bar your finger is over at that moment.

Replies

You need to track the finger position using

func touchesBegan(_ touches: Set<UITouch>,  with event: UIEvent)

and

func touchesMoved(_ touches: Set<UITouch>,  with event: UIEvent)

Then compute which bar it is and display information accordingly in touchesMoved.

  • Did this solve the problem ?

Add a Comment