Skip to content

Commit

Permalink
Merge branch 'sammygutierrez-swift2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Gontovnik committed Sep 20, 2016
2 parents 613ba12 + 0e30f7b commit 8d742ff
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 162 deletions.
40 changes: 20 additions & 20 deletions DGElasticPullToRefresh/DGElasticPullToRefreshExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public extension NSObject {
// MARK: -
// MARK: Vars

private struct dg_associatedKeys {
fileprivate struct dg_associatedKeys {
static var observersArray = "observers"
}

private var dg_observers: [[String : NSObject]] {
fileprivate var dg_observers: [[String : NSObject]] {
get {
if let observers = objc_getAssociatedObject(self, &dg_associatedKeys.observersArray) as? [[String : NSObject]] {
return observers
Expand All @@ -56,20 +56,20 @@ public extension NSObject {
// MARK: -
// MARK: Methods

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

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

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

if let index = dg_observers.indexOf({ $0 == observerInfo}) {
dg_observers.removeAtIndex(index)
if let index = dg_observers.index(where: { $0 == observerInfo}) {
dg_observers.remove(at: index)
removeObserver(observer, forKeyPath: keyPath)
}
}
Expand All @@ -83,11 +83,11 @@ public extension UIScrollView {

// MARK: - Vars

private struct dg_associatedKeys {
fileprivate struct dg_associatedKeys {
static var pullToRefreshView = "pullToRefreshView"
}

private var pullToRefreshView: DGElasticPullToRefreshView? {
fileprivate var pullToRefreshView: DGElasticPullToRefreshView? {
get {
return objc_getAssociatedObject(self, &dg_associatedKeys.pullToRefreshView) as? DGElasticPullToRefreshView
}
Expand All @@ -99,8 +99,8 @@ public extension UIScrollView {

// MARK: - Methods (Public)

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

let pullToRefreshView = DGElasticPullToRefreshView()
Expand All @@ -118,11 +118,11 @@ public extension UIScrollView {
pullToRefreshView?.removeFromSuperview()
}

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

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

Expand All @@ -135,8 +135,8 @@ public extension UIScrollView {
// MARK: (UIView) Extension

public extension UIView {
func dg_center(usePresentationLayerIfPossible: Bool) -> CGPoint {
if usePresentationLayerIfPossible, let presentationLayer = layer.presentationLayer() as? CALayer {
func dg_center(_ usePresentationLayerIfPossible: Bool) -> CGPoint {
if usePresentationLayerIfPossible, let presentationLayer = layer.presentation() {
// Position can be used as a center, because anchorPoint is (0.5, 0.5)
return presentationLayer.position
}
Expand All @@ -149,16 +149,16 @@ public extension UIView {

public extension UIPanGestureRecognizer {
func dg_resign() {
enabled = false
enabled = true
isEnabled = false
isEnabled = true
}
}

// MARK: -
// MARK: (UIGestureRecognizerState) Extension

public extension UIGestureRecognizerState {
func dg_isAnyOf(values: [UIGestureRecognizerState]) -> Bool {
return values.contains({ $0 == self })
func dg_isAnyOf(_ values: [UIGestureRecognizerState]) -> Bool {
return values.contains(where: { $0 == self })
}
}
12 changes: 6 additions & 6 deletions DGElasticPullToRefresh/DGElasticPullToRefreshLoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ SOFTWARE.

import UIKit

public class DGElasticPullToRefreshLoadingView: UIView {
open class DGElasticPullToRefreshLoadingView: UIView {

// MARK: -
// MARK: Vars

lazy var maskLayer: CAShapeLayer = {
let maskLayer = CAShapeLayer()
maskLayer.backgroundColor = UIColor.clearColor().CGColor
maskLayer.fillColor = UIColor.blackColor().CGColor
maskLayer.backgroundColor = UIColor.clear.cgColor
maskLayer.fillColor = UIColor.black.cgColor
maskLayer.actions = ["path" : NSNull(), "position" : NSNull(), "bounds" : NSNull()]
self.layer.mask = maskLayer
return maskLayer
Expand All @@ -58,15 +58,15 @@ public class DGElasticPullToRefreshLoadingView: UIView {
// MARK: -
// MARK: Methods

public func setPullProgress(progress: CGFloat) {
open func setPullProgress(_ progress: CGFloat) {

}

public func startAnimating() {
open func startAnimating() {

}

public func stopLoading() {
open func stopLoading() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public extension CGFloat {
// MARK: -
// MARK: DGElasticPullToRefreshLoadingViewCircle

public class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoadingView {
open class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoadingView {

// MARK: -
// MARK: Vars

private let kRotationAnimation = "kRotationAnimation"
fileprivate let kRotationAnimation = "kRotationAnimation"

private let shapeLayer = CAShapeLayer()
private lazy var identityTransform: CATransform3D = {
fileprivate let shapeLayer = CAShapeLayer()
fileprivate lazy var identityTransform: CATransform3D = {
var transform = CATransform3DIdentity
transform.m34 = CGFloat(1.0 / -500.0)
transform = CATransform3DRotate(transform, CGFloat(-90.0).toRadians(), 0.0, 0.0, 1.0)
Expand All @@ -66,8 +66,8 @@ public class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoad
super.init(frame: .zero)

shapeLayer.lineWidth = 1.0
shapeLayer.fillColor = UIColor.clearColor().CGColor
shapeLayer.strokeColor = tintColor.CGColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = tintColor.cgColor
shapeLayer.actions = ["strokeEnd" : NSNull(), "transform" : NSNull()]
shapeLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
layer.addSublayer(shapeLayer)
Expand All @@ -80,7 +80,7 @@ public class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoad
// MARK: -
// MARK: Methods

override public func setPullProgress(progress: CGFloat) {
override open func setPullProgress(_ progress: CGFloat) {
super.setPullProgress(progress)

shapeLayer.strokeEnd = min(0.9 * progress, 0.9)
Expand All @@ -93,46 +93,46 @@ public class DGElasticPullToRefreshLoadingViewCircle: DGElasticPullToRefreshLoad
}
}

override public func startAnimating() {
override open func startAnimating() {
super.startAnimating()

if shapeLayer.animationForKey(kRotationAnimation) != nil { return }
if shapeLayer.animation(forKey: kRotationAnimation) != nil { return }

let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.toValue = CGFloat(2 * M_PI) + currentDegree()
rotationAnimation.duration = 1.0
rotationAnimation.repeatCount = Float.infinity
rotationAnimation.removedOnCompletion = false
rotationAnimation.isRemovedOnCompletion = false
rotationAnimation.fillMode = kCAFillModeForwards
shapeLayer.addAnimation(rotationAnimation, forKey: kRotationAnimation)
shapeLayer.add(rotationAnimation, forKey: kRotationAnimation)
}

override public func stopLoading() {
override open func stopLoading() {
super.stopLoading()

shapeLayer.removeAnimationForKey(kRotationAnimation)
shapeLayer.removeAnimation(forKey: kRotationAnimation)
}

private func currentDegree() -> CGFloat {
return shapeLayer.valueForKeyPath("transform.rotation.z") as! CGFloat
fileprivate func currentDegree() -> CGFloat {
return shapeLayer.value(forKeyPath: "transform.rotation.z") as! CGFloat
}

override public func tintColorDidChange() {
override open func tintColorDidChange() {
super.tintColorDidChange()

shapeLayer.strokeColor = tintColor.CGColor
shapeLayer.strokeColor = tintColor.cgColor
}

// MARK: -
// MARK: Layout

override public func layoutSubviews() {
override open func layoutSubviews() {
super.layoutSubviews()

shapeLayer.frame = bounds

let inset = shapeLayer.lineWidth / 2.0
shapeLayer.path = UIBezierPath(ovalInRect: CGRectInset(shapeLayer.bounds, inset, inset)).CGPath
shapeLayer.path = UIBezierPath(ovalIn: shapeLayer.bounds.insetBy(dx: inset, dy: inset)).cgPath
}

}
Loading

0 comments on commit 8d742ff

Please sign in to comment.