Skip to content

Commit

Permalink
Hopefully finally fixed view controller animation
Browse files Browse the repository at this point in the history
  • Loading branch information
SamusAranX committed Sep 23, 2019
1 parent a3ca0d1 commit da9ebc1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Sources/Preferences/PreferencesTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,11 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont

view.removeConstraints(activeChildViewConstraints)

fromViewController.view.layer?.opacity = 0
toViewController.view.layer?.opacity = 0
transition(
from: fromViewController,
to: toViewController,
options: []
) {
toViewController.view.layer?.opacity = 1
self.activeChildViewConstraints = toViewController.view.constrainToSuperviewBounds()
}
}
Expand All @@ -135,12 +132,30 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont
options: NSViewController.TransitionOptions = [],
completionHandler completion: (() -> Void)? = nil
) {
// Ensure views have layers
fromViewController.view.wantsLayer = true
toViewController.view.wantsLayer = true

// Make views invisible before animation starts
fromViewController.view.layer?.opacity = 0
toViewController.view.layer?.opacity = 0

// Start window frame animation
setWindowFrame(for: toViewController, animated: true)

// Do the VC transition
super.transition(
from: fromViewController,
to: toViewController,
options: [],
options: options,
completionHandler: completion
)

// Make destination VC visible after animation has ended
// Assuming of course that macOS's animation takes 250ms to run
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
toViewController.view.layer?.opacity = 1
}
}

private func setWindowFrame(for viewController: NSViewController, animated: Bool = false) {
Expand Down

0 comments on commit da9ebc1

Please sign in to comment.