-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIViewPushPopAnimationExtension.swift
More file actions
46 lines (41 loc) · 1.5 KB
/
UIViewPushPopAnimationExtension.swift
File metadata and controls
46 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// UIViewPushPopAnimationExtension.swift
// HeroExample
//
// Created by hanwe lee on 2020/09/18.
//
import UIKit
extension UIView {
enum UIViewSlidePushDirection {
case left
case right
}
func slidePush(duration: TimeInterval = 0.3, completionDelegate: AnyObject? = nil,direction:UIViewSlidePushDirection,completeHandler:@escaping () -> ()) {
self.alpha = 0.4
UIView.animate(withDuration: duration, delay: 0, options: .curveEaseOut, animations: {
self.alpha = 1.0
}, completion: {[weak self] (finished: Bool) -> Void in
completeHandler()
})
let slidePushTransition = CATransition()
if let delegate: AnyObject = completionDelegate {
slidePushTransition.delegate = delegate as? CAAnimationDelegate
}
slidePushTransition.type = CATransitionType.push
var subType:CATransitionSubtype = .fromRight
switch direction {
case .left:
subType = .fromLeft
break
case .right:
subType = .fromRight
break
}
slidePushTransition.subtype = subType
slidePushTransition.duration = duration
slidePushTransition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)
slidePushTransition.fillMode = CAMediaTimingFillMode.removed
slidePushTransition.startProgress = 0.85
self.layer.add(slidePushTransition, forKey: "slidePushTransition")
}
}