_SwiftSupport.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Created by David Jennes on 7/10/18.
  3. // Copyright © 2018 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. /// Note: this file has a `_` in the filename on purpose, to ensure it is the
  7. /// first compiled file. See:
  8. /// https://bugs.swift.org/browse/SR-631
  9. /// Swift < 4.2 support
  10. #if !(swift(>=4.2))
  11. enum CAMediaTimingFunctionName {
  12. static let linear = kCAMediaTimingFunctionLinear
  13. static let easeIn = kCAMediaTimingFunctionEaseIn
  14. static let easeOut = kCAMediaTimingFunctionEaseOut
  15. static let easeInEaseOut = kCAMediaTimingFunctionEaseInEaseOut
  16. static let `default` = kCAMediaTimingFunctionDefault
  17. }
  18. enum CAMediaTimingFillMode {
  19. static let forwards = kCAFillModeForwards
  20. }
  21. enum CAShapeLayerFillRule {
  22. static let evenOdd = kCAFillRuleEvenOdd
  23. }
  24. enum CAShapeLayerLineCap {
  25. static let round = kCALineCapRound
  26. }
  27. enum CAShapeLayerLineJoin {
  28. static let round = kCALineJoinRound
  29. }
  30. public typealias CATransitionSubtype = String
  31. extension CATransitionSubtype {
  32. static let fromBottom = kCATransitionFromBottom
  33. static let fromLeft = kCATransitionFromLeft
  34. static let fromRight = kCATransitionFromRight
  35. static let fromTop = kCATransitionFromTop
  36. }
  37. public extension CGRect {
  38. func inset(by insets: UIEdgeInsets) -> CGRect {
  39. return UIEdgeInsetsInsetRect(self, insets)
  40. }
  41. }
  42. extension NSCoder {
  43. class func cgPoint(for string: String) -> CGPoint {
  44. return CGPointFromString(string)
  45. }
  46. }
  47. public extension UIBlurEffect {
  48. typealias Style = UIBlurEffectStyle
  49. }
  50. extension UIControl {
  51. typealias State = UIControlState
  52. }
  53. public extension UINavigationController {
  54. typealias Operation = UINavigationControllerOperation
  55. }
  56. extension UIResponder {
  57. static let keyboardAnimationDurationUserInfoKey = UIKeyboardAnimationDurationUserInfoKey
  58. static let keyboardFrameEndUserInfoKey = UIKeyboardFrameEndUserInfoKey
  59. static let keyboardWillHideNotification = NSNotification.Name.UIKeyboardWillHide
  60. static let keyboardWillShowNotification = NSNotification.Name.UIKeyboardWillShow
  61. }
  62. extension UITextView {
  63. static let textDidChangeNotification = NSNotification.Name.UITextViewTextDidChange
  64. }
  65. extension UIView {
  66. typealias AnimationOptions = UIViewAnimationOptions
  67. func sendSubviewToBack(_ view: UIView) {
  68. sendSubview(toBack: view)
  69. }
  70. func bringSubviewToFront(_ view: UIView) {
  71. bringSubview(toFront: view)
  72. }
  73. }
  74. extension UIViewController {
  75. func willMove(toParent parent: UIViewController?) {
  76. willMove(toParentViewController: parent)
  77. }
  78. func didMove(toParent parent: UIViewController?) {
  79. didMove(toParentViewController: parent)
  80. }
  81. func addChild(_ childController: UIViewController) {
  82. addChildViewController(childController)
  83. }
  84. func removeFromParent() {
  85. removeFromParentViewController()
  86. }
  87. }
  88. #endif