@@ -19,6 +19,53 @@ import PromiseKit
1919 import PromiseKit
2020*/
2121public extension UIView {
22+ #if swift(>=4.2)
23+ /**
24+ Animate changes to one or more views using the specified duration, delay,
25+ options, and completion handler.
26+
27+ - Parameter duration: The total duration of the animations, measured in
28+ seconds. If you specify a negative value or 0, the changes are made
29+ without animating them.
30+
31+ - Parameter delay: The amount of time (measured in seconds) to wait before
32+ beginning the animations. Specify a value of 0 to begin the animations
33+ immediately.
34+
35+ - Parameter options: A mask of options indicating how you want to perform the
36+ animations. For a list of valid constants, see UIViewAnimationOptions.
37+
38+ - Parameter animations: A block object containing the changes to commit to the
39+ views.
40+
41+ - Returns: A promise that fulfills with a boolean NSNumber indicating
42+ whether or not the animations actually finished.
43+ */
44+ @discardableResult
45+ static func animate( _: PMKNamespacer , duration: TimeInterval , delay: TimeInterval = 0 , options: UIView . AnimationOptions = [ ] , animations: @escaping ( ) -> Void ) -> Guarantee < Bool > {
46+ return Guarantee { animate ( withDuration: duration, delay: delay, options: options, animations: animations, completion: $0) }
47+ }
48+
49+ @discardableResult
50+ static func animate( _: PMKNamespacer , duration: TimeInterval , delay: TimeInterval , usingSpringWithDamping damping: CGFloat , initialSpringVelocity: CGFloat , options: UIView . AnimationOptions = [ ] , animations: @escaping ( ) -> Void ) -> Guarantee < Bool > {
51+ return Guarantee { animate ( withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: $0) }
52+ }
53+
54+ @discardableResult
55+ static func transition( _: PMKNamespacer , with view: UIView , duration: TimeInterval , options: UIView . AnimationOptions = [ ] , animations: ( ( ) -> Void ) ? ) -> Guarantee < Bool > {
56+ return Guarantee { transition ( with: view, duration: duration, options: options, animations: animations, completion: $0) }
57+ }
58+
59+ @discardableResult
60+ static func transition( _: PMKNamespacer , from: UIView , to: UIView , duration: TimeInterval , options: UIView . AnimationOptions = [ ] ) -> Guarantee < Bool > {
61+ return Guarantee { transition ( from: from, to: to, duration: duration, options: options, completion: $0) }
62+ }
63+
64+ @discardableResult
65+ static func perform( _: PMKNamespacer , animation: UIView . SystemAnimation , on views: [ UIView ] , options: UIView . AnimationOptions = [ ] , animations: ( ( ) -> Void ) ? ) -> Guarantee < Bool > {
66+ return Guarantee { perform ( animation, on: views, options: options, animations: animations, completion: $0) }
67+ }
68+ #else
2269 /**
2370 Animate changes to one or more views using the specified duration, delay,
2471 options, and completion handler.
@@ -64,4 +111,5 @@ public extension UIView {
64111 static func perform( _: PMKNamespacer , animation: UISystemAnimation , on views: [ UIView ] , options: UIViewAnimationOptions = [ ] , animations: ( ( ) -> Void ) ? ) -> Guarantee < Bool > {
65112 return Guarantee { perform ( animation, on: views, options: options, animations: animations, completion: $0) }
66113 }
114+ #endif
67115}
0 commit comments