Skip to content

Commit dfcb351

Browse files
committed
Fix hiding animation (closes #40)
1 parent 42a3b93 commit dfcb351

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

SideMenu/MenuItemsAnimator.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ private func TransformForRotatingLayer(_ layer: CALayer, angle: CGFloat) -> CATr
1818
}
1919

2020
class MenuItemsAnimator {
21-
22-
var completion: (() -> Void)?
23-
var duration: TimeInterval = 0
21+
var completion: () -> Void = {}
22+
var duration: CFTimeInterval = 0
2423

2524
fileprivate let layers: [CALayer]
2625
fileprivate let startAngle: CGFloat
@@ -34,19 +33,18 @@ class MenuItemsAnimator {
3433

3534
func start() {
3635
let count = Double(layers.count)
37-
let duration = self.duration * count / (4 * count - 3)
36+
let animationDuration = self.duration * count / (4 * count - 3)
3837
for (index, layer) in layers.enumerated() {
3938
layer.transform = TransformForRotatingLayer(layer, angle: startAngle)
4039

41-
let delay = 3 * duration * Double(index) / count
42-
UIView.animate(withDuration: duration, delay: delay, options: .curveEaseIn, animations: {
40+
let delay = 3 * animationDuration * Double(index) / count
41+
UIView.animate(withDuration: animationDuration, delay: delay, options: .curveEaseIn, animations: {
4342
layer.transform = TransformForRotatingLayer(layer, angle: self.endAngle)
4443
}, completion: nil)
4544
}
4645

47-
let delay = DispatchTime.now() + Double(Int64(duration * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
48-
DispatchQueue.main.asyncAfter(deadline: delay) {
49-
self.completion?()
46+
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
47+
self.completion()
5048
}
5149
}
5250
}

0 commit comments

Comments
 (0)