Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animating NSTabView Views

I am trying to animate each view of NSTabView with a slide in when the view is selected. I have this working in a fashion, but it only animates the first time i select a new tab view. After that i do not see an animation when switching tab views, although i can see the the function is fired every time.?

override func tabView(tabView: NSTabView, didSelectTabViewItem tabViewItem: NSTabViewItem) {
    tabViewItem.view!.setFrameOrigin(NSPoint(x: tabViewItem.view!.frame.origin.x + 300, y: tabViewItem.view!.frame.origin.y))
    tabViewItem.view!.animator().setFrameOrigin(NSPoint(x: tabViewItem.view!.frame.origin.x - 300, y: tabViewItem.view!.frame.origin.y))
    // i can see this fires every time i switch tab views but the animation only works the fist time
}
like image 329
Gary Simpson Avatar asked Nov 22 '22 08:11

Gary Simpson


1 Answers

If you're using NSTabViewController. You only need to set transitionOptions inside viewDidLoad Method.

class TabVC: NSTabViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        /// When new tab will select, it will perform slide transition.
        self.transitionOptions = .slideRight
    }
    
}
like image 158
M Afham Avatar answered Mar 03 '23 14:03

M Afham