1

I am trying to have a view appear with an animation, but all I get is

> NSViewAnimation target is not view or window ((null))

Which is strange, because I am pretty sure the target I add is a view. I tried running the animation from the VC of the superview:

    if let popoverVC = storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "NewEventPopoverViewController")) as? NewEventPopoverViewController {
        self.popoverVC = popoverVC

        let myView = popoverVC.view

        self.view.addSubview(myView)

        let animation = NSViewAnimation.init(viewAnimations: [[.target: myView], [.startFrame: myView.frame.insetBy(dx: 20, dy: 20)], [.endFrame: myView.frame], [.effect: NSViewAnimation.EffectName.fadeIn]])
        animation.duration = TimeInterval(1)
        animation.start()
    }

Because that didn’t work I also tried running the animation from the view’s VC itself:

override func viewDidLoad() {
    super.viewDidLoad()

    let animation = NSViewAnimation.init(viewAnimations: [[.target: self.view], [.startFrame: self.view.frame.insetBy(dx: 20, dy: 20)], [.endFrame: self.view.frame], [.effect: NSViewAnimation.EffectName.fadeIn]])
    animation.duration = TimeInterval(1)
    animation.start()
}

But I only get the same error message again.

chl
  • 380
  • 3
  • 18

0 Answers0