diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift index cf71bff..774aa5a 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift @@ -183,8 +183,8 @@ public extension UIPanGestureRecognizer { // MARK: - // MARK: (UIGestureRecognizerState) Extension -public extension UIGestureRecognizerState { - func dg_isAnyOf(values: [UIGestureRecognizerState]) -> Bool { - return values.contains({ $0 == self }) +public extension UIGestureRecognizer.State { + func dg_isAnyOf(_ values: [UIGestureRecognizer.State]) -> Bool { + return values.contains(where: { $0 == self }) } } diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift index b3cdd2b..90dacc6 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift @@ -99,11 +99,11 @@ public class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoad if shapeLayer.animationForKey(kRotationAnimation) != nil { return } let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z") - rotationAnimation.toValue = CGFloat(2 * M_PI) + currentDegree() + rotationAnimation.toValue = CGFloat(2 * Double.pi) + currentDegree() rotationAnimation.duration = 1.0 rotationAnimation.repeatCount = Float.infinity rotationAnimation.removedOnCompletion = false - rotationAnimation.fillMode = kCAFillModeForwards + rotationAnimation.fillMode = CAMediaTimingFillMode.forwards shapeLayer.addAnimation(rotationAnimation, forKey: kRotationAnimation) } diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift index 152af8c..80ec6bd 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift @@ -124,7 +124,7 @@ public class DGElasticPullToRefreshView: UIView { super.init(frame: CGRect.zero) displayLink = CADisplayLink(target: self, selector: Selector("displayLinkTick")) - displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSRunLoopCommonModes) + displayLink.add(to: RunLoop.main, forMode: RunLoop.Mode.common) displayLink.paused = true shapeLayer.backgroundColor = UIColor.clearColor().CGColor @@ -141,7 +141,7 @@ public class DGElasticPullToRefreshView: UIView { addSubview(r2ControlPointView) addSubview(r3ControlPointView) - NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("applicationWillEnterForeground"), name: UIApplicationWillEnterForegroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DGElasticPullToRefreshView.applicationWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) } required public init?(coder aDecoder: NSCoder) { @@ -175,8 +175,10 @@ public class DGElasticPullToRefreshView: UIView { } else if keyPath == DGElasticPullToRefreshConstants.KeyPaths.Frame { layoutSubviews() } else if keyPath == DGElasticPullToRefreshConstants.KeyPaths.PanGestureRecognizerState { - if let gestureState = scrollView()?.panGestureRecognizer.state where gestureState.dg_isAnyOf([.Ended, .Cancelled, .Failed]) { - scrollViewDidChangeContentOffset(dragging: false) + if let gestureState = scrollView()?.panGestureRecognizer.state { + if gestureState == .ended || gestureState == .cancelled || gestureState == .failed { + scrollViewDidChangeContentOffset(dragging: false) + } } } } @@ -184,7 +186,7 @@ public class DGElasticPullToRefreshView: UIView { // MARK: - // MARK: Notifications - func applicationWillEnterForeground() { + @objc func applicationWillEnterForeground() { if state == .Loading { layoutSubviews() } @@ -336,7 +338,7 @@ public class DGElasticPullToRefreshView: UIView { displayLink.paused = true } - func displayLinkTick() { + @objc func displayLinkTick() { let width = bounds.width var height: CGFloat = 0.0