NotifierUI // Improve fading animations.

This commit is contained in:
ShikiSuen 2023-02-24 14:43:42 +08:00
parent e6e99c5205
commit 36e6634247
1 changed files with 18 additions and 10 deletions

View File

@ -152,27 +152,35 @@ extension Notifier {
} }
} }
private func fadeIn() { private func performDisplayLifetime() {
guard let window = window else { return } guard let window = window else { return }
let afterRect = window.frame Self.instanceSet.insert(self, at: 0)
var afterRect = window.frame
var beforeRect = afterRect var beforeRect = afterRect
beforeRect.origin.x -= 20 beforeRect.origin.x -= 20
window.setFrame(beforeRect, display: true) window.setFrame(beforeRect, display: true)
window.orderFront(self) window.orderFront(self)
window.setFrame(afterRect, display: true, animate: true) window.setFrame(afterRect, display: true, animate: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.3) {
beforeRect = window.frame
afterRect = window.frame
afterRect.origin.x += 20
window.setFrame(afterRect, display: true, animate: true)
self.close()
Self.instanceSet.remove(self)
}
} }
private func display() { private func display() {
Self.instanceSet.arrayOfWindows.forEach { Self.instanceSet.arrayOfWindows.enumerated().forEach { id, theInstance in
$0.alphaValue -= 0.1 theInstance.alphaValue *= Double(pow(0.4, Double(id + 1)))
$0.contentView?.subviews.forEach { $0.alphaValue *= 0.5 } theInstance.contentView?.subviews.forEach {
$0.alphaValue *= Double(pow(0.6, Double(id + 1)))
}
} }
shiftExistingWindowPositions() shiftExistingWindowPositions()
fadeIn() DispatchQueue.main.async {
Self.instanceSet.insert(self, at: 0) self.performDisplayLifetime()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.3) {
self.close()
Self.instanceSet.remove(self)
} }
} }
} }