swift中的NSWindow翻译动画

我正在尝试在延迟后为 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 坐标,但到目前为止还没有成功。

sadsasafsa 回答:swift中的NSWindow翻译动画

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/4225.html

大家都在问