I'm trying to animate an NSPanel
after a delay.
class ViewController: NSViewController {
var alertPanel = NSPanel()
func removePanel(){
NSAnimationContext.runAnimationGroup { (cont) in
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { //delays 1 second
cont.duration = 0.2
let box = self.alertPanel.frame
var xCor = box.origin.x
xCor += 300
let rect = CGRect(x: xCor, y: box.origin.y, width: box.width, height: box.height)
self.alertPanel.animator().setFrame(rect, display: true, animate: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.alertPanel.close()
}
}
}
}
}
The window is suppose move to the right until it moves out of the screen. But currently the window doesn't full move out of view (always stops at the same point).
So far I've tried changing the duration and the x coordinate, but so far no luck.