Home > Blockchain >  Possible to animate NSSwitch when changing state programatically?
Possible to animate NSSwitch when changing state programatically?

Time:11-09

I am controlling an NSSwitch state in a function. I declared trigger1ToggleOut outlet earlier, when I trigger the function the switch turns on, but it happens instantly, without the sliding animation. Is there a way to make it animate? (like you can do with progress indicators)

func turnSwitchOn()
    {
      trigger1ToggleOut.state = .on
    }

Any help would be great.

CodePudding user response:

Adding my comment as answer, Quoting from enter image description here

CodePudding user response:

You can declare switch as -

var mySwitch = UISwitch()

Setting the switch on

mySwitch.setOn(true, animated: true)

For turning it off

mySwitch.setOn(false, animated: true)

This will animate while changing the state.

  • Related