0

The following code from here shows how to do a fade-out for NSView in Swift:

NSAnimationContext.runAnimationGroup({ context in
    context.duration = 1
    self.view.animator().alphaValue = 0
}, completionHandler: {
    self.view.isHidden = true
    self.view.alphaValue = 1
})

I am using this code to display a status notification -> i.e. the text appears, stays for around a few seconds, and then fades out. Is there a way to delay the start of the fade out to accomplish this?

Cheetaiean
  • 901
  • 1
  • 12
  • 26

1 Answers1

2

Is there a way to delay the start of the fade out to accomplish this?

One way is to use NSTimer to run your animation after whatever delay you choose. For example, you could pass a block containing your code to +scheduledTimerWithTimeInterval:repeats:block:, and once the interval expires the block will run.

Caleb
  • 124,013
  • 19
  • 183
  • 272