Skip to content

Commit

Permalink
Ignoring scrolling/zooming gestures on the bottom static line view #3
Browse files Browse the repository at this point in the history
  • Loading branch information
mozharovsky committed Nov 26, 2016
1 parent 9b19183 commit a98aa2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class CropViewController: UIViewController, FloatingViewLayout, Cropable {
updateContent()
}

var recognizersAdded = false
fileprivate var recognizersAdded = false
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

Expand Down Expand Up @@ -153,10 +153,10 @@ final class CropViewController: UIViewController, FloatingViewLayout, Cropable {
}

func updateCropViewScrolling() {
if state == .folded || state == .moved {
cropView.isUserInteractionEnabled = false
if state == .moved {
delegate.isEnabled = false
} else {
cropView.isUserInteractionEnabled = true
delegate.isEnabled = true
}
}

Expand Down
34 changes: 30 additions & 4 deletions Source/CropableScrollViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ open class CropableScrollViewDelegate<T: Cropable>: NSObject, UIScrollViewDelega

open let linesView = LinesView()

fileprivate var panning = false
/// Indicates whether cropping should or should not be enabled for using.
open var isEnabled = true {
didSet {
if isEnabled {
cropable.cropView.isScrollEnabled = true
} else {
cropable.highlightArea(false, animated: false)
cropable.cropView.isScrollEnabled = false
}
}
}

fileprivate var isPanning = false

// MARK: Initialization

public init(cropable: T) {
self.cropable = cropable
Expand All @@ -25,32 +39,42 @@ open class CropableScrollViewDelegate<T: Cropable>: NSObject, UIScrollViewDelega
// MARK: UIScrollViewDelegate

open func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
guard isEnabled else { return }

cropable.willZoom()
}

open func scrollViewDidZoom(_ scrollView: UIScrollView) {
guard isEnabled else { return }

cropable.didZoom()
}

open func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard isEnabled else { return }

if cropable.alwaysShowGuidelines {
cropable.highlightArea(true)
}

guard panning else {
guard isPanning else {
return
}

cropable.highlightArea(true)
}

open func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
panning = true
guard isEnabled else { return }

isPanning = true
cropable.highlightArea(true)
}

open func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
panning = false
guard isEnabled else { return }

isPanning = false

if cropable.alwaysShowGuidelines {
cropable.highlightArea(true, animated: false)
Expand All @@ -60,6 +84,8 @@ open class CropableScrollViewDelegate<T: Cropable>: NSObject, UIScrollViewDelega
}

open func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
guard isEnabled else { return }

cropable.willEndZooming()
cropable.didEndZooming()
}
Expand Down

0 comments on commit a98aa2f

Please sign in to comment.