mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 01:31:42 +00:00
Simplify ViewFader
and avoid second-guessing when to hard-set opacity.
This commit is contained in:
parent
4bc0b75c30
commit
33cc1154a2
@ -746,7 +746,6 @@ class MachineDocument:
|
||||
/// CoreAnimation.
|
||||
private class ViewFader: NSObject, CAAnimationDelegate {
|
||||
private var views: [NSView]
|
||||
private var opacity: Float = 0.0
|
||||
|
||||
init(views: [NSView]) {
|
||||
self.views = views
|
||||
@ -755,12 +754,6 @@ class MachineDocument:
|
||||
}
|
||||
}
|
||||
|
||||
func animationDidStart(_ anim: CAAnimation) {
|
||||
for view in views {
|
||||
view.layer!.opacity = opacity
|
||||
}
|
||||
}
|
||||
|
||||
func animationDidStop(_ animation: CAAnimation, finished: Bool) {
|
||||
if finished {
|
||||
for view in views {
|
||||
@ -770,22 +763,18 @@ class MachineDocument:
|
||||
}
|
||||
|
||||
func animateIn() {
|
||||
opacity = 1.0
|
||||
|
||||
for view in views {
|
||||
view.layer?.removeAllAnimations()
|
||||
view.isHidden = false
|
||||
view.layer?.opacity = 1.0
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(delay : TimeInterval) {
|
||||
// Do nothing if already animating out.
|
||||
// Do nothing if already animating out or invisible.
|
||||
if views[0].isHidden || views[0].layer?.animation(forKey: "opacity") != nil {
|
||||
return
|
||||
}
|
||||
|
||||
opacity = 0.0
|
||||
for view in views {
|
||||
let fadeAnimation = CABasicAnimation(keyPath: "opacity")
|
||||
fadeAnimation.beginTime = CACurrentMediaTime() + delay
|
||||
@ -794,6 +783,9 @@ class MachineDocument:
|
||||
fadeAnimation.duration = 0.2
|
||||
fadeAnimation.delegate = self
|
||||
|
||||
fadeAnimation.fillMode = .forwards
|
||||
fadeAnimation.isRemovedOnCompletion = false
|
||||
|
||||
view.layer?.removeAllAnimations()
|
||||
view.layer!.add(fadeAnimation, forKey: "opacity")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user