diff --git a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj index b7267dce..c116a66c 100644 --- a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj +++ b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj @@ -12,7 +12,7 @@ 29D699E91B70ABFC0021FA73 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29D699E71B70ABFC0021FA73 /* LaunchScreen.xib */; }; 29D699F51B70ABFC0021FA73 /* ImagePickerDemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D699F41B70ABFC0021FA73 /* ImagePickerDemoTests.swift */; }; 29D699FF1B70ACD50021FA73 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 29D699FE1B70ACD50021FA73 /* Podfile */; }; - C3771E008DA39CF04754C8A9 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 733A7AD0105A657A80502E72 /* Pods.framework */; }; + C3771E008DA39CF04754C8A9 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 733A7AD0105A657A80502E72 /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ diff --git a/Demo/ImagePickerDemo/Podfile.lock b/Demo/ImagePickerDemo/Podfile.lock index d2693185..51a6e652 100644 --- a/Demo/ImagePickerDemo/Podfile.lock +++ b/Demo/ImagePickerDemo/Podfile.lock @@ -6,9 +6,9 @@ DEPENDENCIES: EXTERNAL SOURCES: ImagePicker: - :path: "../../" + :path: ../../ SPEC CHECKSUMS: ImagePicker: 32becfa25b8e9179e60c45411b577340d35e3e32 -COCOAPODS: 0.39.0 +COCOAPODS: 0.39.0.beta.4 diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 3c00157d..9d56c675 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -107,8 +107,7 @@ class ImageStackView: UIView { extension ImageStackView { func imageDidPush(notification: NSNotification) { - //TODO indexOf in swift 2 - let emptyView = views.filter {$0.image == nil}.first + let emptyView = views.filter { $0.image == nil }.first if let emptyView = emptyView { animateImageView(emptyView) diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index d076416c..ae42c734 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -73,7 +73,7 @@ class CameraView: UIViewController { }() let captureSession = AVCaptureSession() - let devices = AVCaptureDevice.devices() + var devices = AVCaptureDevice.devices() var captureDevice: AVCaptureDevice? { didSet { if let currentDevice = captureDevice { @@ -121,6 +121,8 @@ class CameraView: UIViewController { let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) + if devices.isEmpty { devices = AVCaptureDevice.devices() } + for device in devices { if let device = device as? AVCaptureDevice where device.hasMediaType(AVMediaTypeVideo) { if authorizationStatus == .Authorized { diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index 06041dd4..b21a182a 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -85,7 +85,7 @@ public class ImageGalleryView: UIView { }() weak var delegate: ImageGalleryPanGestureDelegate? - var collectionSize: CGSize! + var collectionSize: CGSize? var shouldTransform = false var imagesBeforeLoading = 0 var fetchResult: PHFetchResult? @@ -159,8 +159,10 @@ public class ImageGalleryView: UIView { // MARK: - Pan gesture recognizer func handlePanGestureRecognizer(gesture: UIPanGestureRecognizer) { - let translation = gesture.translationInView(superview!) - let velocity = gesture.velocityInView(superview!) + guard let superview = superview else { return } + + let translation = gesture.translationInView(superview) + let velocity = gesture.velocityInView(superview) switch gesture.state { case .Began: @@ -176,12 +178,15 @@ public class ImageGalleryView: UIView { // MARK: - Private helpers func getImage(name: String) -> UIImage { - let bundlePath = NSBundle(forClass: self.classForCoder).resourcePath?.stringByAppendingString("/ImagePicker.bundle") - let bundle = NSBundle(path: bundlePath!) + guard let bundlePath = NSBundle(forClass: self.classForCoder).resourcePath?.stringByAppendingString("/ImagePicker.bundle") else { return UIImage() } + + let bundle = NSBundle(path: bundlePath) let traitCollection = UITraitCollection(displayScale: 3) - let image = UIImage(named: name, inBundle: bundle, compatibleWithTraitCollection: traitCollection) + + guard let image = UIImage(named: name, inBundle: bundle, compatibleWithTraitCollection: traitCollection) + else { return UIImage() } - return image! + return image } func displayNoImagesMessage(hideCollectionView: Bool) { @@ -231,6 +236,8 @@ extension ImageGalleryView: UICollectionViewDelegateFlowLayout { public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { + guard let collectionSize = collectionSize else { return CGSizeZero } + return collectionSize } } @@ -240,7 +247,9 @@ extension ImageGalleryView: UICollectionViewDelegateFlowLayout { extension ImageGalleryView: UICollectionViewDelegate { public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { - let cell = collectionView.cellForItemAtIndexPath(indexPath) as! ImageGalleryViewCell + guard let cell = collectionView.cellForItemAtIndexPath(indexPath) + as? ImageGalleryViewCell else { return } + let asset = assets[indexPath.row] Photos.resolveAsset(asset) { image in @@ -264,12 +273,13 @@ extension ImageGalleryView: UICollectionViewDelegate { } } - public func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { - guard indexPath.row + 10 >= assets.count - && indexPath.row < fetchResult?.count - && canFetchImages else { return } + public func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, + forItemAtIndexPath indexPath: NSIndexPath) { + guard indexPath.row + 10 >= assets.count + && indexPath.row < fetchResult?.count + && canFetchImages else { return } - fetchPhotos() - canFetchImages = false + fetchPhotos() + canFetchImages = false } } diff --git a/Source/ImageGallery/ImageGalleryViewCell.swift b/Source/ImageGallery/ImageGalleryViewCell.swift index 256759a2..ab419a50 100644 --- a/Source/ImageGallery/ImageGalleryViewCell.swift +++ b/Source/ImageGallery/ImageGalleryViewCell.swift @@ -14,6 +14,7 @@ class ImageGalleryViewCell: UICollectionViewCell { override init(frame: CGRect) { super.init(frame: frame) + for view in [imageView, selectedImageView] { view.contentMode = .ScaleAspectFill view.translatesAutoresizingMaskIntoConstraints = false @@ -24,7 +25,7 @@ class ImageGalleryViewCell: UICollectionViewCell { } required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") + fatalError("init(coder:) has not been implemented") } // MARK: - Configuration diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 96f4fc23..25d78454 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -213,6 +213,7 @@ public class ImagePickerController: UIViewController { extension ImagePickerController: BottomContainerViewDelegate { func pickerButtonDidPress() { + bottomContainer.pickerButton.enabled = false bottomContainer.stackView.startLoader() collapseGalleryView { [unowned self] in self.cameraController.takePicture() @@ -247,6 +248,7 @@ extension ImagePickerController: CameraViewDelegate { self.stack.pushAsset(asset) } galleryView.shouldTransform = true + bottomContainer.pickerButton.enabled = true UIView.animateWithDuration(0.3, animations: { self.galleryView.collectionView.transform = CGAffineTransformMakeTranslation(self.galleryView.collectionSize.width, 0) diff --git a/Source/TopView/TopView.swift b/Source/TopView/TopView.swift index 14c5c693..0cdabff2 100644 --- a/Source/TopView/TopView.swift +++ b/Source/TopView/TopView.swift @@ -95,8 +95,10 @@ class TopView: UIView { // MARK: - Private helpers func getImage(name: String) -> UIImage { - let bundlePath = NSBundle(forClass: self.classForCoder).resourcePath?.stringByAppendingString("/ImagePicker.bundle") - let bundle = NSBundle(path: bundlePath!) + guard let bundlePath = NSBundle(forClass: self.classForCoder).resourcePath?.stringByAppendingString("/ImagePicker.bundle") + else { return UIImage() } + + let bundle = NSBundle(path: bundlePath) let traitCollection = UITraitCollection(displayScale: 3) guard let image = UIImage(named: name, inBundle: bundle, compatibleWithTraitCollection: traitCollection) else { return UIImage() }