我正在尝试在延迟后为 NSPanel
设置动画。
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()
}
}
}
}
}
假设窗口向右移动,直到它移出屏幕。但目前窗口并没有完全移出视野(总是停在同一点)。
到目前为止,我已经尝试更改持续时间和 x 坐标,但到目前为止还没有成功。