Skip to content

Commit

Permalink
Merge pull request #129 from aashishdhawan/bug/imagelimit
Browse files Browse the repository at this point in the history
Fix Image Limit bug
  • Loading branch information
zenangst committed Apr 5, 2016
2 parents 80ab6cf + 87d46aa commit 07a0004
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
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

0 comments on commit 07a0004

Please sign in to comment.