Skip to content
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
16 changes: 12 additions & 4 deletions Source/PullToRefreshView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
//
import UIKit

/*
Fix: Simultaneous access to memory due to KVO

For more information regarding this global variable follow the followinf links:
1. https://developer.apple.com/swift/blog/?id=6
2. http://michael-brown.net/2017/swift-and-kvo-context-variables/
*/
private var kvoContext = "PullToRefreshKVOContext"

open class PullToRefreshView: UIView {
enum PullToRefreshState {
case pulling
Expand All @@ -19,14 +28,13 @@ 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 {
Expand Down Expand Up @@ -78,7 +86,7 @@ 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

Expand Down Expand Up @@ -262,7 +270,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)
}

Expand Down
4 changes: 2 additions & 2 deletions Source/UIScrollViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public extension UIScrollView {
return pullToRefreshView as? PullToRefreshView
}

public func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) {
public 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)?) {
public 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
Expand Down