Skip to content

Commit

Permalink
Merge pull request #24 from Athlee/develop-v0.1.3
Browse files Browse the repository at this point in the history
[ATHImagePickerController] Develop v0.1.3
  • Loading branch information
mozharovsky authored Jan 31, 2017
2 parents 988658c + 716d66b commit 193db2a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Source/ATHImagePickerAssetsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 48 additions & 5 deletions Source/ATHImagePickerPreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@
import UIKit
import ImagePickerKit

// MARK: - Internal Protocols & Implementations

internal protocol EmbededController {
var holder: SelectionController! { get set }
}

internal final class ATHImagePickerCropableScrollViewDelegate<T: Cropable>: CropableScrollViewDelegate<T> 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 }
Expand All @@ -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 }
}
Expand Down Expand Up @@ -94,7 +120,8 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl
}

lazy var delegate: CropableScrollViewDelegate<ATHImagePickerPreviewViewController> = {
return CropableScrollViewDelegate(cropable: self)
let delegate = ATHImagePickerCropableScrollViewDelegate(cropable: self)
return delegate
}()

// MARK: Properties
Expand Down Expand Up @@ -157,6 +184,10 @@ open class ATHImagePickerPreviewViewController: UIViewController, EmbededControl
holder.isScrollEnabled = false
}

open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
holder.isScrollEnabled = false
}

open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
holder.isScrollEnabled = true
}
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions Source/ATHImagePickerSelectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 193db2a

Please sign in to comment.