Shifting NSView also shifts other views for no apparent reason

Viewed 33

Through my code I shift the main view (self.view) using an animator() with the following code:

NSAnimationContext.runAnimationGroup({ (_) in
    NSAnimationContext.current.duration = 0.5
    self.view.animator().frame.origin.x = 380

}) {
    print("finished")
}

And it does successfully shift my view, nevertheless I encounter an issue when adding another view to my main window using the following code:

let newView = NSView(frame: NSRect(x: 0, y: 0, width: 500, height: 500))
newView.wantsLayer = true
newView.layer?.backgroundColor = CGColor(red: 150/255, green: 15/255, blue: 240/255, alpha: 1)
NSApplication.shared.mainWindow?.contentView?.addSubview(newView)

I don't understand why this newView which is not associated to the other view shifts accordingly to self.view even if the main window presents the newView.

Thanks.

0 Answers
Related