diff --git a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerAssetsViewController.swift b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerAssetsViewController.swift index fc47a2e..0accd4f 100644 --- a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerAssetsViewController.swift +++ b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerAssetsViewController.swift @@ -12,13 +12,14 @@ import ImagePickerKit public protocol AssetsController: class { var offset: CGPoint { get set } + var collectionView: UICollectionView! { get set } } open class ATHImagePickerAssetsViewController: UIViewController, AssetsController, EmbededController { // MARK: - Outlets - @IBOutlet weak var collectionView: UICollectionView! + @IBOutlet public weak var collectionView: UICollectionView! // MARK: - AssetsController properties diff --git a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerPreviewViewController.swift b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerPreviewViewController.swift index 77615b2..30a8a0d 100644 --- a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerPreviewViewController.swift +++ b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerPreviewViewController.swift @@ -9,6 +9,35 @@ import UIKit import ImagePickerKit +// MARK: - Internal Protocols & Implementations + +internal protocol EmbededController { + var holder: SelectionController! { get set } +} + +internal final class ATHImagePickerCropableScrollViewDelegate: CropableScrollViewDelegate where T: AnyObject { + internal var didScroll: ((Void) -> Void)? + internal var didStartScrolling: ((Void) -> Void)? + internal var didEndScrolling: ((Void) -> Void)? + + override func scrollViewDidScroll(_ scrollView: UIScrollView) { + super.scrollViewDidScroll(scrollView) + didScroll?() + } + + override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { + super.scrollViewWillBeginDragging(scrollView) + didStartScrolling?() + } + + override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + super.scrollViewDidEndDragging(scrollView, willDecelerate: decelerate) + didEndScrolling?() + } +} + +// MARK: - Public Protocols & Implementations + public protocol SelectionController: class { var previewController: PreviewController? { get set } var assetsController: AssetsController? { get set } @@ -18,15 +47,12 @@ public protocol SelectionController: class { var offset: CGPoint { get set } var isScrollEnabled: Bool { get set } + var isBouncing: Bool { get set } var isTracking: Bool { get } func commit(error: ATHImagePickerError) } -internal protocol EmbededController { - var holder: SelectionController! { get set } -} - public protocol PreviewController: FloatingViewLayout { var image: UIImage? { get set } } @@ -94,7 +120,8 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl } lazy var delegate: CropableScrollViewDelegate = { - return CropableScrollViewDelegate(cropable: self) + let delegate = ATHImagePickerCropableScrollViewDelegate(cropable: self) + return delegate }() // MARK: Properties @@ -157,6 +184,10 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl holder.isScrollEnabled = false } + open override func touchesMoved(_ touches: Set, with event: UIEvent?) { + holder.isScrollEnabled = false + } + open override func touchesEnded(_ touches: Set, with event: UIEvent?) { holder.isScrollEnabled = true } @@ -197,6 +228,18 @@ extension ATHImagePickerPreviewViewController { } @IBAction func didRecognizeCheckPan(_ rec: UIPanGestureRecognizer) { + if holder.isTracking { + UIView.animate(withDuration: 0.3, animations: { + self.holder.isScrollEnabled = false + }) + } else { + holder.isScrollEnabled = false + } + + if rec.state == .ended || rec.state == .cancelled { + holder.isScrollEnabled = true + } + guard !isZooming && !holder.isTracking else { return } allowPanOutside = true } diff --git a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerSelectionViewController.swift b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerSelectionViewController.swift index 0473b05..2eeb59b 100644 --- a/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerSelectionViewController.swift +++ b/Examples/ATHImagePickerController/Storyboard/TestPicker/Pods/ATHKit/Source/ATHImagePickerSelectionViewController.swift @@ -56,6 +56,16 @@ open class ATHImagePickerSelectionViewController: UIViewController, SelectionCon } } + public var isBouncing: Bool = true { + didSet { + pageTabBarController?.isBounceEnabled = isBouncing + + if !isBouncing { + pageTabBarController?.scrollView?.contentOffset = .zero + } + } + } + public var isTracking: Bool { return pageTabBarController?.isTracking ?? false } diff --git a/Source/ATHImagePickerAssetsViewController.swift b/Source/ATHImagePickerAssetsViewController.swift index fc47a2e..0accd4f 100644 --- a/Source/ATHImagePickerAssetsViewController.swift +++ b/Source/ATHImagePickerAssetsViewController.swift @@ -12,13 +12,14 @@ import ImagePickerKit public protocol AssetsController: class { var offset: CGPoint { get set } + var collectionView: UICollectionView! { get set } } open class ATHImagePickerAssetsViewController: UIViewController, AssetsController, EmbededController { // MARK: - Outlets - @IBOutlet weak var collectionView: UICollectionView! + @IBOutlet public weak var collectionView: UICollectionView! // MARK: - AssetsController properties diff --git a/Source/ATHImagePickerPreviewViewController.swift b/Source/ATHImagePickerPreviewViewController.swift index 77615b2..30a8a0d 100644 --- a/Source/ATHImagePickerPreviewViewController.swift +++ b/Source/ATHImagePickerPreviewViewController.swift @@ -9,6 +9,35 @@ import UIKit import ImagePickerKit +// MARK: - Internal Protocols & Implementations + +internal protocol EmbededController { + var holder: SelectionController! { get set } +} + +internal final class ATHImagePickerCropableScrollViewDelegate: CropableScrollViewDelegate where T: AnyObject { + internal var didScroll: ((Void) -> Void)? + internal var didStartScrolling: ((Void) -> Void)? + internal var didEndScrolling: ((Void) -> Void)? + + override func scrollViewDidScroll(_ scrollView: UIScrollView) { + super.scrollViewDidScroll(scrollView) + didScroll?() + } + + override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { + super.scrollViewWillBeginDragging(scrollView) + didStartScrolling?() + } + + override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { + super.scrollViewDidEndDragging(scrollView, willDecelerate: decelerate) + didEndScrolling?() + } +} + +// MARK: - Public Protocols & Implementations + public protocol SelectionController: class { var previewController: PreviewController? { get set } var assetsController: AssetsController? { get set } @@ -18,15 +47,12 @@ public protocol SelectionController: class { var offset: CGPoint { get set } var isScrollEnabled: Bool { get set } + var isBouncing: Bool { get set } var isTracking: Bool { get } func commit(error: ATHImagePickerError) } -internal protocol EmbededController { - var holder: SelectionController! { get set } -} - public protocol PreviewController: FloatingViewLayout { var image: UIImage? { get set } } @@ -94,7 +120,8 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl } lazy var delegate: CropableScrollViewDelegate = { - return CropableScrollViewDelegate(cropable: self) + let delegate = ATHImagePickerCropableScrollViewDelegate(cropable: self) + return delegate }() // MARK: Properties @@ -157,6 +184,10 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl holder.isScrollEnabled = false } + open override func touchesMoved(_ touches: Set, with event: UIEvent?) { + holder.isScrollEnabled = false + } + open override func touchesEnded(_ touches: Set, with event: UIEvent?) { holder.isScrollEnabled = true } @@ -197,6 +228,18 @@ extension ATHImagePickerPreviewViewController { } @IBAction func didRecognizeCheckPan(_ rec: UIPanGestureRecognizer) { + if holder.isTracking { + UIView.animate(withDuration: 0.3, animations: { + self.holder.isScrollEnabled = false + }) + } else { + holder.isScrollEnabled = false + } + + if rec.state == .ended || rec.state == .cancelled { + holder.isScrollEnabled = true + } + guard !isZooming && !holder.isTracking else { return } allowPanOutside = true } diff --git a/Source/ATHImagePickerSelectionViewController.swift b/Source/ATHImagePickerSelectionViewController.swift index 0473b05..2eeb59b 100644 --- a/Source/ATHImagePickerSelectionViewController.swift +++ b/Source/ATHImagePickerSelectionViewController.swift @@ -56,6 +56,16 @@ open class ATHImagePickerSelectionViewController: UIViewController, SelectionCon } } + public var isBouncing: Bool = true { + didSet { + pageTabBarController?.isBounceEnabled = isBouncing + + if !isBouncing { + pageTabBarController?.scrollView?.contentOffset = .zero + } + } + } + public var isTracking: Bool { return pageTabBarController?.isTracking ?? false }