5 // Created by Hori,Masaki on 2017/12/23.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 protocol ViewAnimationTerget {}
12 extension NSView: ViewAnimationTerget {}
13 extension NSWindow: ViewAnimationTerget {}
15 struct ViewAnimationAttributes {
17 private(set) var animations: [NSViewAnimation.Key: Any]
19 init(target: ViewAnimationTerget, startFrame: NSRect? = nil, endFrame: NSRect? = nil, effect: NSViewAnimation.EffectName? = nil ) {
21 animations = [.target: target]
22 animations[.startFrame] = startFrame
23 animations[.endFrame] = endFrame
24 animations[.effect] = effect
27 var startFrame: NSRect? {
29 get { return animations[.startFrame] as? NSRect }
30 set { animations[.startFrame] = newValue }
33 var endFrame: NSRect? {
35 get { return animations[.endFrame] as? NSRect }
36 set { animations[.endFrame] = newValue }
39 var effect: NSViewAnimation.EffectName? {
41 get { return animations[.effect] as? NSViewAnimation.EffectName }
42 set { animations[.effect] = newValue }
46 class ViewAnimation: NSViewAnimation, NSAnimationDelegate {
48 var completeHandler: (() -> Void)?
50 init(viewAnimations: [ViewAnimationAttributes]) {
52 super.init(viewAnimations: viewAnimations.map { $0.animations })
55 required init?(coder: NSCoder) {
57 fatalError("Can not initialize with NSCoder")
60 func start(completeHandler: @escaping () -> Void) {
63 self.completeHandler = completeHandler
69 func animationDidEnd(_ animation: NSAnimation) {