Skip to content

Commit da9ebc1

Browse files
committed
Hopefully finally fixed view controller animation
1 parent a3ca0d1 commit da9ebc1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Sources/Preferences/PreferencesTabViewController.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont
117117

118118
view.removeConstraints(activeChildViewConstraints)
119119

120-
fromViewController.view.layer?.opacity = 0
121-
toViewController.view.layer?.opacity = 0
122120
transition(
123121
from: fromViewController,
124122
to: toViewController,
125123
options: []
126124
) {
127-
toViewController.view.layer?.opacity = 1
128125
self.activeChildViewConstraints = toViewController.view.constrainToSuperviewBounds()
129126
}
130127
}
@@ -135,12 +132,30 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont
135132
options: NSViewController.TransitionOptions = [],
136133
completionHandler completion: (() -> Void)? = nil
137134
) {
135+
// Ensure views have layers
136+
fromViewController.view.wantsLayer = true
137+
toViewController.view.wantsLayer = true
138+
139+
// Make views invisible before animation starts
140+
fromViewController.view.layer?.opacity = 0
141+
toViewController.view.layer?.opacity = 0
142+
143+
// Start window frame animation
144+
setWindowFrame(for: toViewController, animated: true)
145+
146+
// Do the VC transition
138147
super.transition(
139148
from: fromViewController,
140149
to: toViewController,
141-
options: [],
150+
options: options,
142151
completionHandler: completion
143152
)
153+
154+
// Make destination VC visible after animation has ended
155+
// Assuming of course that macOS's animation takes 250ms to run
156+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
157+
toViewController.view.layer?.opacity = 1
158+
}
144159
}
145160

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

0 commit comments

Comments
 (0)