Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

兼容swift5 #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
22 changes: 11 additions & 11 deletions DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public extension NSObject {
// MARK: -
// MARK: Methods

public func dg_addObserver(_ observer: NSObject, forKeyPath keyPath: String) {
func dg_addObserver(_ observer: NSObject, forKeyPath keyPath: String) {
let observerInfo = [keyPath : observer]

if dg_observers.index(where: { $0 == observerInfo }) == nil {
if dg_observers.firstIndex(where: { $0 == observerInfo }) == nil {
dg_observers.append(observerInfo)
addObserver(observer, forKeyPath: keyPath, options: .new, context: nil)
}
}

public func dg_removeObserver(_ observer: NSObject, forKeyPath keyPath: String) {
func dg_removeObserver(_ observer: NSObject, forKeyPath keyPath: String) {
let observerInfo = [keyPath : observer]

if let index = dg_observers.index(where: { $0 == observerInfo}) {
if let index = dg_observers.firstIndex(where: { $0 == observerInfo}) {
dg_observers.remove(at: index)
removeObserver(observer, forKeyPath: keyPath)
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public extension UIScrollView {

// MARK: - Methods (Public)

public func dg_addPullToRefreshWithActionHandler(_ actionHandler: @escaping () -> Void, loadingView: DGElasticPullToRefreshLoadingView?) {
func dg_addPullToRefreshWithActionHandler(_ actionHandler: @escaping () -> Void, loadingView: DGElasticPullToRefreshLoadingView?) {
isMultipleTouchEnabled = false
panGestureRecognizer.maximumNumberOfTouches = 1

Expand All @@ -112,21 +112,21 @@ public extension UIScrollView {
pullToRefreshView.observing = true
}

public func dg_removePullToRefresh() {
func dg_removePullToRefresh() {
pullToRefreshView?.disassociateDisplayLink()
pullToRefreshView?.observing = false
pullToRefreshView?.removeFromSuperview()
}

public func dg_setPullToRefreshBackgroundColor(_ color: UIColor) {
func dg_setPullToRefreshBackgroundColor(_ color: UIColor) {
pullToRefreshView?.backgroundColor = color
}

public func dg_setPullToRefreshFillColor(_ color: UIColor) {
func dg_setPullToRefreshFillColor(_ color: UIColor) {
pullToRefreshView?.fillColor = color
}

public func dg_stopLoading() {
func dg_stopLoading() {
pullToRefreshView?.stopLoading()
}
}
Expand Down Expand Up @@ -157,8 +157,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 })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ open class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoadin
rotationAnimation.duration = 1.0
rotationAnimation.repeatCount = Float.infinity
rotationAnimation.isRemovedOnCompletion = false
rotationAnimation.fillMode = kCAFillModeForwards
rotationAnimation.fillMode = CAMediaTimingFillMode.forwards
shapeLayer.add(rotationAnimation, forKey: kRotationAnimation)
}

Expand Down
8 changes: 4 additions & 4 deletions DGElasticPullToRefresh/DGElasticPullToRefreshView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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: .common)
displayLink.isPaused = true

shapeLayer.backgroundColor = UIColor.clear.cgColor
Expand All @@ -141,7 +141,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) {
Expand Down Expand Up @@ -193,7 +193,7 @@ open class DGElasticPullToRefreshView: UIView {
// MARK: -
// MARK: Notifications

func applicationWillEnterForeground() {
@objc func applicationWillEnterForeground() {
if state == .loading {
layoutSubviews()
}
Expand Down Expand Up @@ -355,7 +355,7 @@ open class DGElasticPullToRefreshView: UIView {
displayLink.isPaused = true
}

func displayLinkTick() {
@objc func displayLinkTick() {
let width = bounds.width
var height: CGFloat = 0.0

Expand Down
5 changes: 3 additions & 2 deletions DGElasticPullToRefreshExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -274,7 +275,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGElasticPullToRefreshExample;
PRODUCT_NAME = DGElasticPullToRefreshExample;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -287,7 +288,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGElasticPullToRefreshExample;
PRODUCT_NAME = DGElasticPullToRefreshExample;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>DGElasticPullToRefreshExample.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>