diff --git a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj index 826f753..ff82e1d 100644 --- a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj +++ b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj @@ -212,6 +212,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -394,7 +395,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -407,7 +408,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example/PullToRefreshSwift/AppDelegate.swift b/Example/PullToRefreshSwift/AppDelegate.swift index 6350b56..396700a 100644 --- a/Example/PullToRefreshSwift/AppDelegate.swift +++ b/Example/PullToRefreshSwift/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + internal func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { return true } diff --git a/Example/PullToRefreshSwift/ViewController.swift b/Example/PullToRefreshSwift/ViewController.swift index daa8430..4e0b5da 100644 --- a/Example/PullToRefreshSwift/ViewController.swift +++ b/Example/PullToRefreshSwift/ViewController.swift @@ -50,7 +50,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Cell") + let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "Cell") cell.textLabel?.font = UIFont.italicSystemFont(ofSize: 18) cell.textLabel?.textColor = UIColor(red: 44/255, green: 62/255, blue: 88/255, alpha: 1.0) cell.textLabel?.text = texts[(indexPath as NSIndexPath).row] diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index 28658f7..4e84672 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -7,6 +7,8 @@ // import UIKit +private var kvoContext = "PullToRefreshKVOContext" + open class PullToRefreshView: UIView { enum PullToRefreshState { case pulling @@ -19,14 +21,12 @@ open class PullToRefreshView: UIView { // MARK: Variables let contentOffsetKeyPath = "contentOffset" let contentSizeKeyPath = "contentSize" - var kvoContext = "PullToRefreshKVOContext" - fileprivate var options: PullToRefreshOption fileprivate var backgroundView: UIView fileprivate var arrow: UIImageView fileprivate var indicator: UIActivityIndicatorView fileprivate var scrollViewInsets: UIEdgeInsets = UIEdgeInsets.zero - fileprivate var refreshCompletion: ((Void) -> Void)? + fileprivate var refreshCompletion: (() -> Void)? fileprivate var pull: Bool = true fileprivate var positionY:CGFloat = 0 { @@ -78,13 +78,13 @@ open class PullToRefreshView: UIView { fatalError("init(coder:) has not been implemented") } - public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :((Void) -> Void)?, down:Bool=true) { + public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :(() -> Void)?, down:Bool=true) { self.options = options self.refreshCompletion = refreshCompletion self.backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) self.backgroundView.backgroundColor = self.options.backgroundColor - self.backgroundView.autoresizingMask = UIViewAutoresizing.flexibleWidth + self.backgroundView.autoresizingMask = UIView.AutoresizingMask.flexibleWidth self.arrow = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) self.arrow.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin] @@ -92,7 +92,7 @@ open class PullToRefreshView: UIView { self.arrow.image = UIImage(named: PullToRefreshConst.imageName, in: Bundle(for: type(of: self)), compatibleWith: nil) - self.indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray) + self.indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray) self.indicator.bounds = self.arrow.bounds self.indicator.autoresizingMask = self.arrow.autoresizingMask self.indicator.hidesWhenStopped = true @@ -262,7 +262,7 @@ open class PullToRefreshView: UIView { fileprivate func arrowRotation() { UIView.animate(withDuration: 0.2, delay: 0, options:[], animations: { // -0.0000001 for the rotation direction control - self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI-0.0000001)) + self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi - 0.0000001)) }, completion:nil) } diff --git a/Source/UIScrollViewExtension.swift b/Source/UIScrollViewExtension.swift index 249fe52..8ed8046 100755 --- a/Source/UIScrollViewExtension.swift +++ b/Source/UIScrollViewExtension.swift @@ -14,26 +14,26 @@ public extension UIScrollView { return pullToRefreshView as? PullToRefreshView } - public func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) { + func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) { let refreshViewFrame = CGRect(x: 0, y: -PullToRefreshConst.height, width: self.frame.size.width, height: PullToRefreshConst.height) let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion) refreshView.tag = PullToRefreshConst.pullTag addSubview(refreshView) } - public func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) { + func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) { let refreshViewFrame = CGRect(x: 0, y: contentSize.height, width: self.frame.size.width, height: PullToRefreshConst.height) let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion,down: false) refreshView.tag = PullToRefreshConst.pushTag addSubview(refreshView) } - public func startPullRefresh() { + func startPullRefresh() { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag) refreshView?.state = .refreshing } - public func stopPullRefreshEver(_ ever:Bool = false) { + func stopPullRefreshEver(_ ever:Bool = false) { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag) if ever { refreshView?.state = .finish @@ -42,17 +42,17 @@ public extension UIScrollView { } } - public func removePullRefresh() { + func removePullRefresh() { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag) refreshView?.removeFromSuperview() } - public func startPushRefresh() { + func startPushRefresh() { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag) refreshView?.state = .refreshing } - public func stopPushRefreshEver(_ ever:Bool = false) { + func stopPushRefreshEver(_ ever:Bool = false) { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag) if ever { refreshView?.state = .finish @@ -61,13 +61,13 @@ public extension UIScrollView { } } - public func removePushRefresh() { + func removePushRefresh() { let refreshView = self.refreshViewWithTag(PullToRefreshConst.pushTag) refreshView?.removeFromSuperview() } // If you want to PullToRefreshView fixed top potision, Please call this function in scrollViewDidScroll - public func fixedPullToRefreshViewForDidScroll() { + func fixedPullToRefreshViewForDidScroll() { let pullToRefreshView = self.refreshViewWithTag(PullToRefreshConst.pullTag) if !PullToRefreshConst.fixedTop || pullToRefreshView == nil { return