From 0a7f600d61d1613fc95b07690fb6890f08a3b762 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Wed, 23 Sep 2015 14:50:12 +0200 Subject: [PATCH 1/4] Bigger quality --- Source/CameraView/CameraView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index 51c62360..b3c85a18 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -71,7 +71,7 @@ class CameraView: UIViewController { // MARK: - Initialize camera func initializeCamera() { - captureSession.sessionPreset = AVCaptureSessionPreset1280x720 + captureSession.sessionPreset = AVCaptureSessionPreset1920x1080 capturedDevices = NSMutableArray() let authorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) From 54766698b04ecf1f26a27db2122b0045d95717f2 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Wed, 23 Sep 2015 14:52:54 +0200 Subject: [PATCH 2/4] Improves the quality --- Source/CameraView/CameraView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index b3c85a18..0497e34e 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -204,7 +204,7 @@ class CameraView: UIViewController { func cropImage(image: UIImage) -> UIImage { guard let imageReference = CGImageCreateWithImageInRect(image.CGImage, - CGRect(x: 0, y: 0, width: image.size.height - 200, height: image.size.width)) else { return UIImage() } + CGRect(x: 0, y: 0, width: image.size.height - 190, height: image.size.width)) else { return UIImage() } let normalizedImage = UIImage(CGImage: imageReference, scale: 1, orientation: .Right) return normalizedImage From 8159ed460c783017b44fc0001ada90eb0ac5f17f Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Wed, 23 Sep 2015 15:25:00 +0200 Subject: [PATCH 3/4] Reloading when needed now. --- Source/ImageGallery/ImageGalleryView.swift | 30 ++++++++++------------ Source/ImagePickerController.swift | 1 + 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index bf39236f..d51e197a 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -113,7 +113,6 @@ public class ImageGalleryView: UIView { topSeparator.addSubview(indicator) imagesBeforeLoading = 0 - fetchPhotos(0) } required public init?(coder aDecoder: NSCoder) { @@ -146,9 +145,9 @@ public class ImageGalleryView: UIView { let authorizationStatus = ALAssetsLibrary.authorizationStatus() let size = CGSizeMake(100, 150) + canFetchImages = false requestOptions.synchronous = true fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: true)] - canFetchImages = false guard authorizationStatus == .Authorized else { return } @@ -159,24 +158,22 @@ public class ImageGalleryView: UIView { guard let fetchResult = self.fetchResult else { return } if fetchResult.count != 0 && index < fetchResult.count { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { imageManager.requestImageForAsset(fetchResult.objectAtIndex(fetchResult.count - 1 - index) as! PHAsset, targetSize: size, contentMode: PHImageContentMode.AspectFill, options: requestOptions, resultHandler: { (image, _) in - if let image = image { - self.images.addObject(image) - if index > self.imagesBeforeLoading + 10 { - dispatch_async(dispatch_get_main_queue()) { - self.collectionView.reloadData() + dispatch_async(dispatch_get_main_queue(), { + if let image = image { + self.images.addObject(image) + if index > self.imagesBeforeLoading + 10 { self.canFetchImages = true + self.collectionView.reloadData() + } else { + self.fetchPhotos(index+1) } - } else { - self.fetchPhotos(index+1) } - } + }) }) - } } else { + self.canFetchImages = true self.collectionView.reloadData() - canFetchImages = true } } @@ -280,11 +277,10 @@ extension ImageGalleryView: UICollectionViewDelegate { } public func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) { - if indexPath.row + 10 >= images.count && indexPath.row + 10 < fetchResult?.count && canFetchImages { + if indexPath.row + 10 >= images.count && indexPath.row < fetchResult?.count && canFetchImages { imagesBeforeLoading = images.count - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { - self.fetchPhotos(self.images.count) - } + fetchPhotos(self.images.count) + canFetchImages = false } } } diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 1f65b838..c531fe83 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -264,6 +264,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { func permissionGranted() { galleryView.fetchPhotos(0) + galleryView.canFetchImages = false cameraController.initializeCamera() enableGestures(true) } From 8cdbfa7e89a2d510ed9458131bb98ca64d470c05 Mon Sep 17 00:00:00 2001 From: Ramon Gilabert Date: Wed, 23 Sep 2015 15:44:24 +0200 Subject: [PATCH 4/4] Spacings --- Source/ImageGallery/ImageGalleryView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index d51e197a..d59be81e 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -166,7 +166,7 @@ public class ImageGalleryView: UIView { self.canFetchImages = true self.collectionView.reloadData() } else { - self.fetchPhotos(index+1) + self.fetchPhotos(index + 1) } } })