0

do you know a way to continuously call a function from a UIBarButtonItem in MDC if the button is kept pressed and then call it once if pressed once? Like a fwd/play behaviour.

UPDATE: I am not using the Storyboard

My button

let ffwButton = UIBarButtonItem(image: #imageLiteral(resourceName: "fwd"), style: .plain, target: self, action: #selector(clickfwd))

Thanks.

czane
  • 392
  • 1
  • 6
  • 18

1 Answers1

1

A UIBarButtonItem does not quite work like a UIButton because it doesn't inherit from UIControl. It has only one target and one action. UIButtons on the other hand inherit from UIControl; therefore you can add target/action pairs for all sorts of interesting control events, including .touchDown and .touchUpInside.

Using a UIButton you could start a timer upon .touchDown that sends events repeatedly and invalidate it upon .touchUpInside.

Since you need a UIBarButtonItem, have a look at its init(customView: UIView) initialiser. It lets you create a UIBarButtonItem with a UIButton inside.

nils
  • 1,786
  • 13
  • 18