diff --git a/.travis.yml b/.travis.yml index 570a71fd..48ea4169 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: objective-c before_install: - brew update -#- brew install carthage - if brew outdated | grep -qx xctool; then brew upgrade xctool; fi script: diff --git a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj index 48e2c154..b28f196a 100644 --- a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj +++ b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/project.pbxproj @@ -50,7 +50,9 @@ DD112158CF9886DE925FED5E /* Frameworks */, A067DFAD5749963FA2D2ADED /* Pods */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; 29D699DA1B70ABFC0021FA73 /* Products */ = { isa = PBXGroup; @@ -345,7 +347,7 @@ baseConfigurationReference = C4392341AC7391C01AD9F350 /* Pods-ImagePickerDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; INFOPLIST_FILE = ImagePickerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -359,7 +361,7 @@ baseConfigurationReference = 6F9E1FF802198DC16F260795 /* Pods-ImagePickerDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; INFOPLIST_FILE = ImagePickerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/Demo/ImagePickerDemo/Podfile.lock b/Demo/ImagePickerDemo/Podfile.lock index 62ce7033..7b90ef24 100644 --- a/Demo/ImagePickerDemo/Podfile.lock +++ b/Demo/ImagePickerDemo/Podfile.lock @@ -11,6 +11,4 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: ImagePicker: 2a904341bbc47c96457de00558d2f8dd186eff7c -PODFILE CHECKSUM: ebbcd890a98cb01cb66183bea63d5e8e97f82923 - -COCOAPODS: 1.0.0.beta.2 +COCOAPODS: 0.39.0 diff --git a/ImagePicker.xcodeproj/project.pbxproj b/ImagePicker.xcodeproj/project.pbxproj index ca102ac9..51521352 100644 --- a/ImagePicker.xcodeproj/project.pbxproj +++ b/ImagePicker.xcodeproj/project.pbxproj @@ -108,7 +108,9 @@ D5DC59AA1C201CC4003BD79B /* Source */, D5DC598C1C201BE1003BD79B /* Products */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; D5DC598C1C201BE1003BD79B /* Products */ = { isa = PBXGroup; diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index c07bbc60..1b2f5ee9 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -102,10 +102,13 @@ class CameraView: UIViewController, CLLocationManagerDelegate { } override func viewDidAppear(animated: Bool) { + super.viewDidAppear(animated) + setCorrectOrientationToPreviewLayer() locationManager.startUpdatingLocation() } override func viewDidDisappear(animated: Bool) { + super.viewDidDisappear(animated) locationManager.stopUpdatingLocation() } @@ -253,24 +256,20 @@ class CameraView: UIViewController, CLLocationManagerDelegate { let queue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL) + guard let stillImageOutput = self.stillImageOutput else { return } + if let videoOrientation = previewLayer?.connection.videoOrientation { - stillImageOutput?.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = videoOrientation + stillImageOutput.connectionWithMediaType(AVMediaTypeVideo).videoOrientation = videoOrientation } - guard let stillImageOutput = self.stillImageOutput else { return } - dispatch_async(queue, { [unowned self] in stillImageOutput.captureStillImageAsynchronouslyFromConnection(stillImageOutput.connectionWithMediaType(AVMediaTypeVideo), completionHandler: { (buffer, error) -> Void in let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer) - guard let imageFromData = UIImage(data: imageData) else { return } - let image = self.cropImage(imageFromData) - let orientation = self.pictureOrientation() - guard let imageCG = image.CGImage else { return } PHPhotoLibrary.sharedPhotoLibrary().performChanges({ - let request = PHAssetChangeRequest.creationRequestForAssetFromImage(UIImage(CGImage: imageCG, scale: 1.0, orientation: orientation)) + let request = PHAssetChangeRequest.creationRequestForAssetFromImage(imageFromData) request.location = self.latestLocation }, completionHandler: { success, error in self.delegate?.imageToLibrary() @@ -279,14 +278,6 @@ class CameraView: UIViewController, CLLocationManagerDelegate { }) } - func cropImage(image: UIImage) -> UIImage { - guard let imageReference = CGImageCreateWithImageInRect(image.CGImage, - CGRect(x: 0, y: 0, width: image.size.height - 285, height: image.size.width)) else { return UIImage() } - let normalizedImage = UIImage(CGImage: imageReference, scale: 1, orientation: .Right) - - return normalizedImage - } - func pictureOrientation() -> UIImageOrientation { switch UIDevice.currentDevice().orientation { case .LandscapeLeft: @@ -421,12 +412,15 @@ class CameraView: UIViewController, CLLocationManagerDelegate { override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) + previewLayer?.frame.size = size + setCorrectOrientationToPreviewLayer() + } + + func setCorrectOrientationToPreviewLayer() { guard let previewLayer = self.previewLayer, connection = previewLayer.connection else { return } - previewLayer.frame.size = size - switch UIDevice.currentDevice().orientation { case .Portrait: connection.videoOrientation = .Portrait diff --git a/Source/Configuration.swift b/Source/Configuration.swift index cbe911ba..bc9863d6 100644 --- a/Source/Configuration.swift +++ b/Source/Configuration.swift @@ -30,4 +30,8 @@ public struct Configuration { // MARK: Dimensions public static var cellSpacing: CGFloat = 2 + + // MARK: Custom behaviour + + public static var collapseCollectionViewWhileShot: Bool = true } diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index 923e07c8..b46e6a64 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -125,6 +125,7 @@ public class ImageGalleryView: UIView { collectionView.delegate = self topSeparator.frame = CGRect(x: 0, y: 0, width: totalWidth, height: Dimensions.galleryBarHeight) + topSeparator.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin] indicator.frame = CGRect(x: (totalWidth - Dimensions.indicatorWidth) / 2, y: (topSeparator.frame.height - Dimensions.indicatorHeight) / 2, width: Dimensions.indicatorWidth, height: Dimensions.indicatorHeight) collectionView.frame = CGRect(x: 0, y: topSeparator.frame.height, width: totalWidth, height: collectionFrame - topSeparator.frame.height) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 191cb78b..3adcfe0f 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -65,14 +65,14 @@ public class ImagePickerController: UIViewController { view.frame = CGRect(x: 0, y: 0, width: 1, height: 1) return view - }() + }() var volume = AVAudioSession.sharedInstance().outputVolume public weak var delegate: ImagePickerDelegate? public var stack = ImageStack() public var imageLimit = 0 - let totalSize = UIScreen.mainScreen().bounds.size + var totalSize: CGSize { return UIScreen.mainScreen().bounds.size } var initialFrame: CGRect? var initialContentOffset: CGPoint? var numberOfCells: Int? @@ -134,7 +134,7 @@ public class ImagePickerController: UIViewController { super.viewWillDisappear(animated) UIApplication.sharedApplication().setStatusBarHidden(statusBarHidden, withAnimation: .Fade) } - + public override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) } @@ -158,7 +158,7 @@ public class ImagePickerController: UIViewController { object: nil) NSNotificationCenter.defaultCenter().addObserver(self, - selector: "adjustButtonTitle:", + selector: "didReloadAssets:", name: ImageStack.Notifications.stackDidReload, object: nil) @@ -168,12 +168,18 @@ public class ImagePickerController: UIViewController { object: nil) } + func didReloadAssets(notification: NSNotification) { + adjustButtonTitle(notification) + galleryView.collectionView.reloadData() + galleryView.collectionView.setContentOffset(CGPointZero, animated: false) + } + func volumeChanged(notification: NSNotification) { guard let slider = volumeView.subviews.filter({ $0 is UISlider }).first as? UISlider, let userInfo = notification.userInfo, let changeReason = userInfo["AVSystemController_AudioVolumeChangeReasonNotificationParameter"] as? String where changeReason == "ExplicitVolumeChange" else { return } - + slider.setValue(volume, animated: false) cameraController.takePicture() } @@ -188,6 +194,18 @@ public class ImagePickerController: UIViewController { // MARK: - Helpers + public override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() + + let galleryHeight: CGFloat = UIScreen.mainScreen().nativeBounds.height == 960 + ? ImageGalleryView.Dimensions.galleryBarHeight + : GestureConstants.minimumHeight + + let y = totalSize.height - bottomContainer.frame.height - galleryHeight + galleryView.frame = CGRect(x: 0, y: y, + width: totalSize.width, height: galleryHeight) + } + public override func prefersStatusBarHidden() -> Bool { return true } @@ -257,9 +275,15 @@ extension ImagePickerController: BottomContainerViewDelegate { bottomContainer.pickerButton.enabled = false bottomContainer.stackView.startLoader() - collapseGalleryView { [unowned self] in + let action: Void -> Void = { [unowned self] in self.cameraController.takePicture() } + + if Configuration.collapseCollectionViewWhileShot { + collapseGalleryView(action) + } else { + action() + } } func doneButtonDidPress() {