0

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.

unknown
  • 788
  • 9
  • 24
  • 1
    I have never heard a guy named 'alertPanel'. And I don't even know under what class you are writing code. – El Tomato Jul 31 '21 at 22:08
  • Question Improved now. – unknown Aug 01 '21 at 02:56
  • Is `xCor += 300` still on the screen? Try `xCor += 3000`. – Willeke Aug 01 '21 at 12:17
  • Already tried that. Stops at the same point no matter what number I give. I have also tried translating the panel out of view on the opposite side of the screen, but again stops with about 100px still visible. – unknown Aug 01 '21 at 13:35

0 Answers0