Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Image Limit bug #129

Merged
merged 2 commits into from
Apr 5, 2016
Merged
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
3 changes: 2 additions & 1 deletion Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate {
}
}

func takePicture() {
func takePicture(completion: () -> ()) {
capturedImageView.frame = view.bounds

UIView.animateWithDuration(0.1, animations: {
Expand Down Expand Up @@ -269,6 +269,7 @@ class CameraView: UIViewController, CLLocationManagerDelegate {
request.location = self.locationManager?.latestLocation
}, completionHandler: { success, error in
self.delegate?.imageToLibrary()
completion()
})
})
})
Expand Down
31 changes: 20 additions & 11 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public protocol ImagePickerDelegate: class {
}

public class ImagePickerController: UIViewController {

struct GestureConstants {
static let maximumHeight: CGFloat = 200
static let minimumHeight: CGFloat = 125
Expand Down Expand Up @@ -74,6 +74,7 @@ public class ImagePickerController: UIViewController {
var numberOfCells: Int?
var statusBarHidden = true

private var isTakingPicture = false
public var doneButtonTitle: String? {
didSet {
if let doneButtonTitle = doneButtonTitle {
Expand Down Expand Up @@ -107,7 +108,7 @@ public class ImagePickerController: UIViewController {

public override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

statusBarHidden = UIApplication.sharedApplication().statusBarHidden
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade)
}
Expand Down Expand Up @@ -174,7 +175,7 @@ public class ImagePickerController: UIViewController {
where changeReason == "ExplicitVolumeChange" else { return }

slider.setValue(volume, animated: false)
cameraController.takePicture()
takePicture()
}

func adjustButtonTitle(notification: NSNotification) {
Expand Down Expand Up @@ -237,19 +238,18 @@ public class ImagePickerController: UIViewController {
topView.flashButton.enabled = enabled
topView.rotateCamera.enabled = Configuration.canRotateCamera
}
}

// MARK: - Action methods

extension ImagePickerController: BottomContainerViewDelegate {

func pickerButtonDidPress() {
guard imageLimit == 0 || imageLimit > galleryView.selectedStack.assets.count else { return }
private func isBelowImageLimit() -> Bool {
return (imageLimit == 0 || imageLimit > galleryView.selectedStack.assets.count)
}

private func takePicture() {
guard isBelowImageLimit() && !isTakingPicture else { return }
isTakingPicture = true
bottomContainer.pickerButton.enabled = false
bottomContainer.stackView.startLoader()
let action: Void -> Void = { [unowned self] in
self.cameraController.takePicture()
self.cameraController.takePicture { self.isTakingPicture = false }
}

if Configuration.collapseCollectionViewWhileShot {
Expand All @@ -258,6 +258,15 @@ extension ImagePickerController: BottomContainerViewDelegate {
action()
}
}
}

// MARK: - Action methods

extension ImagePickerController: BottomContainerViewDelegate {

func pickerButtonDidPress() {
takePicture()
}

func doneButtonDidPress() {
let images = ImagePicker.resolveAssets(stack.assets)
Expand Down