From 65b8702bc67bbff07af6e014f66ae5125428980f Mon Sep 17 00:00:00 2001 From: Christopher Prince Date: Thu, 18 Oct 2018 15:25:36 -0600 Subject: [PATCH 1/2] Enabled optional removal of snap to top on initial animating bounce. --- .../DGElasticPullToRefreshExtensions.swift | 5 +++++ .../DGElasticPullToRefreshView.swift | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift index ab4f89e..6ade23f 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift @@ -126,6 +126,11 @@ public extension UIScrollView { pullToRefreshView?.fillColor = color } + // The default on this is `true`-- which is the original behavior of this Cocoapod. I think that's a bug though. It results in a strange interaction with table views when they have an initial section header. + public func dg_setPullToRefreshSnapToTopOnInitialAnimatingBounce(snap: Bool = true) { + pullToRefreshView?.snapToTopOnInitialAnimatingBounce = snap + } + public func dg_stopLoading() { pullToRefreshView?.stopLoading() } diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift index d393eaf..12636e8 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift @@ -50,6 +50,21 @@ open class DGElasticPullToRefreshView: UIView { // MARK: - // MARK: Vars + var snapToTopOnInitialAnimatingBounce: Bool = true + + fileprivate var _justTransitionedToAnimatingBounce: Bool = false + fileprivate var justTransitionedToAnimatingBounce: Bool { + set { + _justTransitionedToAnimatingBounce = newValue + } + + get { + let result = _justTransitionedToAnimatingBounce + _justTransitionedToAnimatingBounce = false + return result + } + } + fileprivate var _state: DGElasticPullToRefreshState = .stopped fileprivate(set) var state: DGElasticPullToRefreshState { get { return _state } @@ -260,6 +275,7 @@ open class DGElasticPullToRefreshView: UIView { } else if state == .dragging && dragging == false { if offsetY >= DGElasticPullToRefreshConstants.MinOffsetToPull { state = .animatingBounce + justTransitionedToAnimatingBounce = true } else { state = .stopped } @@ -362,7 +378,10 @@ open class DGElasticPullToRefreshView: UIView { if state == .animatingBounce { guard let scrollView = scrollView() else { return } - scrollView.contentInset.top = bounceAnimationHelperView.dg_center(isAnimating()).y + if !justTransitionedToAnimatingBounce || snapToTopOnInitialAnimatingBounce { + scrollView.contentInset.top = bounceAnimationHelperView.dg_center(isAnimating()).y + } + scrollView.contentOffset.y = -scrollView.contentInset.top height = scrollView.contentInset.top - originalContentInsetTop From 427a08ea779d998fefe8e10db8b6e4420b0f7472 Mon Sep 17 00:00:00 2001 From: Christopher Prince Date: Thu, 29 Nov 2018 16:20:03 -0700 Subject: [PATCH 2/2] Update to Swift 4.2 --- .swift-version | 2 +- DGElasticPullToRefresh.podspec | 2 ++ .../DGElasticPullToRefreshExtensions.swift | 4 +-- ...lasticPullToRefreshLoadingViewCircle.swift | 8 ++--- .../DGElasticPullToRefreshView.swift | 8 ++--- .../project.pbxproj | 32 +++++++++++++++++-- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++++ .../xcschemes/xcschememanagement.plist | 14 ++++++++ 8 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 DGElasticPullToRefreshExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 DGElasticPullToRefreshExample.xcodeproj/xcuserdata/chris.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/.swift-version b/.swift-version index 9f55b2c..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.2 diff --git a/DGElasticPullToRefresh.podspec b/DGElasticPullToRefresh.podspec index 9de0d3a..80196ea 100644 --- a/DGElasticPullToRefresh.podspec +++ b/DGElasticPullToRefresh.podspec @@ -12,6 +12,8 @@ Pod::Spec.new do |spec| spec.requires_arc = true + spec.swift_version = '4.2' + spec.ios.deployment_target = '8.0' spec.ios.frameworks = ['UIKit', 'Foundation'] end diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift index 6ade23f..9ba49d3 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift @@ -162,8 +162,8 @@ public extension UIPanGestureRecognizer { // MARK: - // MARK: (UIGestureRecognizerState) Extension -public extension UIGestureRecognizerState { - func dg_isAnyOf(_ values: [UIGestureRecognizerState]) -> Bool { +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 c510baf..3012a0c 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshLoadingViewCircle.swift @@ -32,11 +32,11 @@ import UIKit public extension CGFloat { public func toRadians() -> CGFloat { - return (self * CGFloat(M_PI)) / 180.0 + return (self * CGFloat.pi) / 180.0 } public func toDegrees() -> CGFloat { - return self * 180.0 / CGFloat(M_PI) + return self * 180.0 / CGFloat.pi } } @@ -99,11 +99,11 @@ open class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoadin if shapeLayer.animation(forKey: kRotationAnimation) != nil { return } let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z") - rotationAnimation.toValue = CGFloat(2 * M_PI) + currentDegree() + rotationAnimation.toValue = 2 * CGFloat.pi + currentDegree() rotationAnimation.duration = 1.0 rotationAnimation.repeatCount = Float.infinity rotationAnimation.isRemovedOnCompletion = false - rotationAnimation.fillMode = kCAFillModeForwards + rotationAnimation.fillMode = CAMediaTimingFillMode.forwards shapeLayer.add(rotationAnimation, forKey: kRotationAnimation) } diff --git a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift index 12636e8..cfaaeb3 100644 --- a/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift +++ b/DGElasticPullToRefresh/DGElasticPullToRefreshView.swift @@ -139,7 +139,7 @@ open class DGElasticPullToRefreshView: UIView { super.init(frame: CGRect.zero) displayLink = CADisplayLink(target: self, selector: #selector(DGElasticPullToRefreshView.displayLinkTick)) - displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) + displayLink.add(to: RunLoop.main, forMode: RunLoop.Mode.common) displayLink.isPaused = true shapeLayer.backgroundColor = UIColor.clear.cgColor @@ -156,7 +156,7 @@ open class DGElasticPullToRefreshView: UIView { addSubview(r2ControlPointView) addSubview(r3ControlPointView) - NotificationCenter.default.addObserver(self, selector: #selector(DGElasticPullToRefreshView.applicationWillEnterForeground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DGElasticPullToRefreshView.applicationWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) } required public init?(coder aDecoder: NSCoder) { @@ -208,7 +208,7 @@ open class DGElasticPullToRefreshView: UIView { // MARK: - // MARK: Notifications - func applicationWillEnterForeground() { + @objc func applicationWillEnterForeground() { if state == .loading { layoutSubviews() } @@ -371,7 +371,7 @@ open class DGElasticPullToRefreshView: UIView { displayLink.isPaused = true } - func displayLinkTick() { + @objc func displayLinkTick() { let width = bounds.width var height: CGFloat = 0.0 diff --git a/DGElasticPullToRefreshExample.xcodeproj/project.pbxproj b/DGElasticPullToRefreshExample.xcodeproj/project.pbxproj index c778cf5..30b2179 100644 --- a/DGElasticPullToRefreshExample.xcodeproj/project.pbxproj +++ b/DGElasticPullToRefreshExample.xcodeproj/project.pbxproj @@ -113,11 +113,12 @@ 05CD145D1BBE8FEA00AF4030 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Danil Gontovnik"; TargetAttributes = { 05CD14641BBE8FEA00AF4030 = { CreatedOnToolsVersion = 7.0; + DevelopmentTeam = 4BPBWM9E57; LastSwiftMigration = 0800; }; }; @@ -190,13 +191,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -223,6 +234,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -235,13 +247,23 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -260,6 +282,8 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -269,12 +293,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 4BPBWM9E57; INFOPLIST_FILE = DGElasticPullToRefreshExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGElasticPullToRefreshExample; PRODUCT_NAME = DGElasticPullToRefreshExample; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -282,12 +307,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 4BPBWM9E57; INFOPLIST_FILE = DGElasticPullToRefreshExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGElasticPullToRefreshExample; PRODUCT_NAME = DGElasticPullToRefreshExample; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/DGElasticPullToRefreshExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/DGElasticPullToRefreshExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/DGElasticPullToRefreshExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/DGElasticPullToRefreshExample.xcodeproj/xcuserdata/chris.xcuserdatad/xcschemes/xcschememanagement.plist b/DGElasticPullToRefreshExample.xcodeproj/xcuserdata/chris.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..5056fef --- /dev/null +++ b/DGElasticPullToRefreshExample.xcodeproj/xcuserdata/chris.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + DGElasticPullToRefreshExample.xcscheme_^#shared#^_ + + orderHint + 0 + + + +