From 3265bbefd304b81b45000efdc8064f0e067603f4 Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 19:45:00 +0200 Subject: [PATCH 01/26] Add interface --- Source/BottomView/ImageStack.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Source/BottomView/ImageStack.swift diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift new file mode 100644 index 00000000..14b94fbc --- /dev/null +++ b/Source/BottomView/ImageStack.swift @@ -0,0 +1,22 @@ +import UIKit + +class ImageStack: UIView { + + override init(frame: CGRect) { + super.init(frame: frame) + + } + + func pushImage(image: UIImage) { + + } + + func dropImage(image: UIImage) { + + } + + + required init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} From c62606eea49e1a1e319f62ee3f4b8c5e30ea17bf Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 19:46:48 +0200 Subject: [PATCH 02/26] Add console outputs --- Source/BottomView/ImageStack.swift | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 14b94fbc..2971bc82 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -2,21 +2,20 @@ import UIKit class ImageStack: UIView { - override init(frame: CGRect) { - super.init(frame: frame) + override init(frame: CGRect) { + super.init(frame: frame) - } + } - func pushImage(image: UIImage) { + func pushImage(image: UIImage) { + println("Image pushed") + } - } + func dropImage(image: UIImage) { + println("Image dropped") + } - func dropImage(image: UIImage) { - - } - - - required init(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } } From d5e43e39e41c0313f4d3960965cdb6b147acc1dd Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 20:01:48 +0200 Subject: [PATCH 03/26] Add image storage array --- Source/BottomView/ImageStack.swift | 6 ++++++ Source/ImageGallery/ImageGalleryView.swift | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 2971bc82..fd7ebe33 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -2,17 +2,23 @@ import UIKit class ImageStack: UIView { + var images: NSMutableArray = NSMutableArray() + override init(frame: CGRect) { super.init(frame: frame) } func pushImage(image: UIImage) { + images.insertObject(image, atIndex: 0) println("Image pushed") + println(images) } func dropImage(image: UIImage) { + images.removeObject(image) println("Image dropped") + println(images) } required init(coder aDecoder: NSCoder) { diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index b9f4518b..32db5d30 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -23,6 +23,8 @@ class ImageGalleryView: UIView { static let indicatorHeight: CGFloat = 8 } + var stack: ImageStack = ImageStack() + lazy var collectionView: UICollectionView = { [unowned self] in let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0), collectionViewLayout: self.collectionViewLayout) @@ -263,14 +265,14 @@ extension ImageGalleryView: UICollectionViewDelegate { }, completion: { _ in cell.selectedImageView.image = nil }) - selectedImages.removeObject(image) + stack.dropImage(image) } else { cell.selectedImageView.image = getImage("selectedImageGallery") cell.selectedImageView.transform = CGAffineTransformMakeScale(0, 0) UIView.animateWithDuration(0.2, animations: { _ in cell.selectedImageView.transform = CGAffineTransformIdentity }) - selectedImages.insertObject(image, atIndex: 0) + stack.pushImage(image) } delegate?.imageSelected(selectedImages) From 1c140327491de5b997742f298e3840ee95c8de1e Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 20:04:58 +0200 Subject: [PATCH 04/26] Add array of views --- Source/BottomView/ImageStack.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index fd7ebe33..376b0f84 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -3,6 +3,7 @@ import UIKit class ImageStack: UIView { var images: NSMutableArray = NSMutableArray() + var views: NSMutableArray = NSMutableArray() override init(frame: CGRect) { super.init(frame: frame) From bf514e0ab5a643a2a753b5e44b20424c5620755f Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 23:06:57 +0200 Subject: [PATCH 05/26] Fix affine transform bug --- 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 32db5d30..3e060cba 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -261,7 +261,7 @@ extension ImageGalleryView: UICollectionViewDelegate { if cell.selectedImageView.image != nil { UIView.animateWithDuration(0.2, animations: { [unowned self] in - cell.selectedImageView.transform = CGAffineTransformMakeScale(0, 0) + cell.selectedImageView.transform = CGAffineTransformMakeScale(0.1, 0.1) }, completion: { _ in cell.selectedImageView.image = nil }) From d00b66962330839f2ddc363227ab99f48b5f0f5c Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 23:19:27 +0200 Subject: [PATCH 06/26] Make ImageStack a singleton --- Source/BottomView/ImageStack.swift | 6 ++++++ Source/ImageGallery/ImageGalleryView.swift | 6 ++---- Source/ImageGallery/ImageGalleryViewDataSource.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 376b0f84..0f832d59 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -2,6 +2,8 @@ import UIKit class ImageStack: UIView { + static let sharedStack = ImageStack() + var images: NSMutableArray = NSMutableArray() var views: NSMutableArray = NSMutableArray() @@ -22,6 +24,10 @@ class ImageStack: UIView { println(images) } + func containsImage(image: UIImage) -> Bool { + return images.containsObject(image) + } + required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/Source/ImageGallery/ImageGalleryView.swift b/Source/ImageGallery/ImageGalleryView.swift index 3e060cba..e4b0e55d 100644 --- a/Source/ImageGallery/ImageGalleryView.swift +++ b/Source/ImageGallery/ImageGalleryView.swift @@ -23,8 +23,6 @@ class ImageGalleryView: UIView { static let indicatorHeight: CGFloat = 8 } - var stack: ImageStack = ImageStack() - lazy var collectionView: UICollectionView = { [unowned self] in let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0), collectionViewLayout: self.collectionViewLayout) @@ -265,14 +263,14 @@ extension ImageGalleryView: UICollectionViewDelegate { }, completion: { _ in cell.selectedImageView.image = nil }) - stack.dropImage(image) + ImageStack.sharedStack.dropImage(image) } else { cell.selectedImageView.image = getImage("selectedImageGallery") cell.selectedImageView.transform = CGAffineTransformMakeScale(0, 0) UIView.animateWithDuration(0.2, animations: { _ in cell.selectedImageView.transform = CGAffineTransformIdentity }) - stack.pushImage(image) + ImageStack.sharedStack.pushImage(image) } delegate?.imageSelected(selectedImages) diff --git a/Source/ImageGallery/ImageGalleryViewDataSource.swift b/Source/ImageGallery/ImageGalleryViewDataSource.swift index fac10013..2c013795 100644 --- a/Source/ImageGallery/ImageGalleryViewDataSource.swift +++ b/Source/ImageGallery/ImageGalleryViewDataSource.swift @@ -29,7 +29,7 @@ extension ImageGalleryView: UICollectionViewDataSource { shouldTransform = false } - if selectedImages.containsObject(image) { + if ImageStack.sharedStack.containsImage(image) { cell.selectedImageView.image = getImage("selectedImageGallery") cell.selectedImageView.alpha = 1 cell.selectedImageView.transform = CGAffineTransformIdentity From c2311796bc33e8187d4254043c002636bc261356 Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 23:30:08 +0200 Subject: [PATCH 07/26] Add stub for view generation --- Source/BottomView/ImageStack.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 0f832d59..c25a71d4 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -5,13 +5,21 @@ class ImageStack: UIView { static let sharedStack = ImageStack() var images: NSMutableArray = NSMutableArray() - var views: NSMutableArray = NSMutableArray() + var views: [UIImageView] = [UIImageView]() override init(frame: CGRect) { super.init(frame: frame) } +//let viewSize = CGSize(width: frame.size.width, height: frame.size.height) + + func initializeViews() { + for i in 1...4 { + + } + } + func pushImage(image: UIImage) { images.insertObject(image, atIndex: 0) println("Image pushed") From b0a252e6d077b4604188b93b5dd0b4a1e59f7d40 Mon Sep 17 00:00:00 2001 From: richardoti Date: Mon, 10 Aug 2015 23:30:38 +0200 Subject: [PATCH 08/26] Make scheme shared --- .../xcschemes/ImagePickerDemo.xcscheme | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme diff --git a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme new file mode 100644 index 00000000..106780d4 --- /dev/null +++ b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From d26d0879cdf691dfe8f5c2496d9d927c7fa6c259 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 01:48:17 +0200 Subject: [PATCH 09/26] Separate model (ImageStack) and View (StackView( --- Source/BottomView/ImageStack.swift | 20 +------------- Source/BottomView/StackView.swift | 43 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 Source/BottomView/StackView.swift diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index c25a71d4..d2174c3f 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -1,24 +1,10 @@ import UIKit -class ImageStack: UIView { +struct ImageStack { static let sharedStack = ImageStack() var images: NSMutableArray = NSMutableArray() - var views: [UIImageView] = [UIImageView]() - - override init(frame: CGRect) { - super.init(frame: frame) - - } - -//let viewSize = CGSize(width: frame.size.width, height: frame.size.height) - - func initializeViews() { - for i in 1...4 { - - } - } func pushImage(image: UIImage) { images.insertObject(image, atIndex: 0) @@ -35,8 +21,4 @@ class ImageStack: UIView { func containsImage(image: UIImage) -> Bool { return images.containsObject(image) } - - required init(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } } diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift new file mode 100644 index 00000000..68994108 --- /dev/null +++ b/Source/BottomView/StackView.swift @@ -0,0 +1,43 @@ +import UIKit + +class StackView: UIView { + + let stack: ImageStack = ImageStack.sharedStack + var views: [UIImageView] = { + var array = [UIImageView]() + for i in 1...4 { + array.append(UIImageView()) + } + return array + }() + + lazy var viewSize: CGSize = CGSize(width: self.frame.width * 0.6, height: self.frame.height * 0.6) + + override init(frame: CGRect) { + super.init(frame: frame) + backgroundColor = UIColor.blueColor() + addViews() + layoutSubviews() + } + + func addViews() { + views.map{ self.addSubview($0) } + } + + override func layoutSubviews() { + let m = -4 + for (i, view) in enumerate(views) { + println("a") + var w = i * m + var frame = CGRect(origin: CGPoint(x: w, y: w), size: viewSize) + view.frame = frame + view.backgroundColor = UIColor.redColor() + view.layer.borderColor = UIColor.blackColor().CGColor + view.layer.borderWidth = 1 + } + } + + required init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} From c2be32060066441acf17c389111f6cc3908b588a Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 02:35:12 +0200 Subject: [PATCH 10/26] MVP --- Source/BottomView/ImageStack.swift | 25 ++++++++++++++++++++++++- Source/BottomView/StackView.swift | 19 ++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index d2174c3f..cd2507f1 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -1,19 +1,26 @@ import UIKit +protocol ImageStackDelegate { + func imageStackDidReload() +} + struct ImageStack { - static let sharedStack = ImageStack() + static var sharedStack = ImageStack() var images: NSMutableArray = NSMutableArray() + var delegate: ImageStackDelegate? func pushImage(image: UIImage) { images.insertObject(image, atIndex: 0) + delegate?.imageStackDidReload() println("Image pushed") println(images) } func dropImage(image: UIImage) { images.removeObject(image) + delegate?.imageStackDidReload() println("Image dropped") println(images) } @@ -21,4 +28,20 @@ struct ImageStack { func containsImage(image: UIImage) -> Bool { return images.containsObject(image) } + + func getImages() -> [UIImage] { +// let size = images.count > 4 ? 3 : images.count +// var array = [UIImage]() +// for i in 0...size { +// array.append(images[i] as! UIImage) +// } +// return array + println("b") + var array: [UIImage] = [UIImage]() + for image in images { + println("a") + array.append(image as! UIImage) + } +return array + } } diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 68994108..301a50b3 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -3,6 +3,7 @@ import UIKit class StackView: UIView { let stack: ImageStack = ImageStack.sharedStack + var images: [UIImage] = [UIImage]() var views: [UIImageView] = { var array = [UIImageView]() for i in 1...4 { @@ -16,8 +17,10 @@ class StackView: UIView { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor.blueColor() + addViews() layoutSubviews() + ImageStack.sharedStack.delegate = self } func addViews() { @@ -25,11 +28,11 @@ class StackView: UIView { } override func layoutSubviews() { - let m = -4 + let stride = -4 for (i, view) in enumerate(views) { println("a") - var w = i * m - var frame = CGRect(origin: CGPoint(x: w, y: w), size: viewSize) + var side = i * stride + var frame = CGRect(origin: CGPoint(x: side, y: side), size: viewSize) view.frame = frame view.backgroundColor = UIColor.redColor() view.layer.borderColor = UIColor.blackColor().CGColor @@ -41,3 +44,13 @@ class StackView: UIView { fatalError("init(coder:) has not been implemented") } } + +extension StackView: ImageStackDelegate { + func imageStackDidReload() { + for (index, image) in enumerate(stack.getImages()) { + if index < 4 { + views[index].image = image + } + } + } +} From 24bba2ee78bb180190b2dfb5779a86732e7f547b Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:08:43 +0200 Subject: [PATCH 11/26] Add PUSH to stack --- Source/CameraView/CameraView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CameraView/CameraView.swift b/Source/CameraView/CameraView.swift index dde475ee..80cfdddb 100644 --- a/Source/CameraView/CameraView.swift +++ b/Source/CameraView/CameraView.swift @@ -150,6 +150,7 @@ class CameraView: UIViewController { self.stillImageOutput!.captureStillImageAsynchronouslyFromConnection(self.stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo), completionHandler: { (buffer, error) -> Void in let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer) let image = UIImage(data: imageData) + ImageStack.sharedStack.pushImage(image!) self.delegate?.imageToLibrary(image!) let orientation = ALAssetOrientation(rawValue: image!.imageOrientation.rawValue) let assetsLibrary = ALAssetsLibrary() From 3af3d1eb5ed8dff517ad228237a18da93e1cee70 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:13:03 +0200 Subject: [PATCH 12/26] Drop Wrapper to the floor --- Source/BottomView/BottomContainerView.swift | 50 +-------------------- 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index b6944ad3..f001703d 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -40,13 +40,12 @@ class BottomContainerView: UIView { return button }() - lazy var imageWrapper: ImageWrapper = { - let view = ImageWrapper() + lazy var imageWrapper: StackView = { + let view = StackView(frame: CGRect(x: 0, y: 0, width: 80, height: 80)) view.setTranslatesAutoresizingMaskIntoConstraints(false) return view }() - lazy var configuration: PickerConfiguration = { let configuration = PickerConfiguration() return configuration @@ -157,51 +156,6 @@ class BottomContainerView: UIView { } } - // MARK: - Wrapper methods - - func updateWrapperImages(array: NSMutableArray) { - switch array.count { - case 1: - imageWrapper.firstImageView.image = array.firstObject as? UIImage - imageWrapper.secondImageView.image = nil - imageWrapper.secondImageView.alpha = 0 - if pastCount < 1 { - animateImageView(imageWrapper.firstImageView) - } - case 0: - imageWrapper.firstImageView.image = nil - case 2: - imageWrapper.firstImageView.image = array[1] as? UIImage - imageWrapper.secondImageView.image = array.firstObject as? UIImage - imageWrapper.secondImageView.alpha = 1 - imageWrapper.thirdImageView.alpha = 0 - if pastCount < 2 { - animateImageView(imageWrapper.secondImageView) - } - case 3: - imageWrapper.firstImageView.image = array[2] as? UIImage - imageWrapper.secondImageView.image = array[1] as? UIImage - imageWrapper.thirdImageView.image = array.firstObject as? UIImage - imageWrapper.thirdImageView.alpha = 1 - imageWrapper.fourthImageView.alpha = 0 - if pastCount < 3 { - animateImageView(imageWrapper.thirdImageView) - } - default: - imageWrapper.fourthImageView.alpha = 1 - imageWrapper.firstImageView.image = array.lastObject as? UIImage - imageWrapper.secondImageView.image = array[array.count - 2] as? UIImage - imageWrapper.thirdImageView.image = array[array.count - 3] as? UIImage - imageWrapper.fourthImageView.image = array[array.count - 4] as? UIImage - if pastCount < array.count { - animateImageView(imageWrapper.fourthImageView) - } - } - - pastCount = array.count - pickerButton.photoNumber = array.count - } - private func animateImageView(imageView: UIImageView) { imageView.transform = CGAffineTransformMakeScale(0, 0) From 094bdf91dddf0fff069a971a5fc8083678c533f3 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:56:41 +0200 Subject: [PATCH 13/26] Refactor ImageStack --- Source/BottomView/ImageStack.swift | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index cd2507f1..56766bf9 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -8,40 +8,24 @@ struct ImageStack { static var sharedStack = ImageStack() - var images: NSMutableArray = NSMutableArray() + var images: [UIImage] = [UIImage]() var delegate: ImageStackDelegate? - func pushImage(image: UIImage) { - images.insertObject(image, atIndex: 0) + mutating func pushImage(image: UIImage) { + images.append(image) delegate?.imageStackDidReload() println("Image pushed") println(images) } - func dropImage(image: UIImage) { - images.removeObject(image) + mutating func dropImage(image: UIImage) { + images = images.filter() {$0 != image} delegate?.imageStackDidReload() println("Image dropped") println(images) } func containsImage(image: UIImage) -> Bool { - return images.containsObject(image) - } - - func getImages() -> [UIImage] { -// let size = images.count > 4 ? 3 : images.count -// var array = [UIImage]() -// for i in 0...size { -// array.append(images[i] as! UIImage) -// } -// return array - println("b") - var array: [UIImage] = [UIImage]() - for image in images { - println("a") - array.append(image as! UIImage) - } -return array + return contains(images, image) } } From 4f0de9e32901376b0e3ab4a8ac050c66d851a908 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:56:52 +0200 Subject: [PATCH 14/26] Refactor StackView --- Source/BottomView/StackView.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 301a50b3..8266f102 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -2,8 +2,6 @@ import UIKit class StackView: UIView { - let stack: ImageStack = ImageStack.sharedStack - var images: [UIImage] = [UIImage]() var views: [UIImageView] = { var array = [UIImageView]() for i in 1...4 { @@ -17,21 +15,18 @@ class StackView: UIView { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor.blueColor() + println(views.count) + views.map{ self.addSubview($0) } - addViews() layoutSubviews() ImageStack.sharedStack.delegate = self } - func addViews() { - views.map{ self.addSubview($0) } - } - override func layoutSubviews() { - let stride = -4 + let step = -4 for (i, view) in enumerate(views) { println("a") - var side = i * stride + var side = i * step var frame = CGRect(origin: CGPoint(x: side, y: side), size: viewSize) view.frame = frame view.backgroundColor = UIColor.redColor() @@ -47,7 +42,7 @@ class StackView: UIView { extension StackView: ImageStackDelegate { func imageStackDidReload() { - for (index, image) in enumerate(stack.getImages()) { + for (index, image) in enumerate(ImageStack.sharedStack.images) { if index < 4 { views[index].image = image } From c64a72025e75ce6c2303077a7fa8094c87d07ae7 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:57:08 +0200 Subject: [PATCH 15/26] Comment-out temporarily unused functions --- Source/ImagePickerController.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index b2795a47..92cea454 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -138,7 +138,6 @@ extension ImagePickerController: BottomContainerViewDelegate { func pickerButtonDidPress() { cameraController.takePicture() - bottomContainer.updateWrapperImages(galleryView.selectedImages) let title = galleryView.selectedImages.count != 0 ? self.configuration.doneButtonTitle : self.configuration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) bottomContainer.pickerButton.photoNumber = galleryView.selectedImages.count @@ -168,10 +167,10 @@ extension ImagePickerController: CameraViewDelegate { } func imageToLibrary(image: UIImage) { + ImageStack.sharedStack.pushImage(image) galleryView.images.insertObject(image, atIndex: 0) galleryView.selectedImages.insertObject(image, atIndex: 0) galleryView.shouldTransform = true - bottomContainer.updateWrapperImages(galleryView.selectedImages) let title = galleryView.selectedImages.count != 0 ? self.configuration.doneButtonTitle : self.configuration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) bottomContainer.pickerButton.photoNumber = galleryView.selectedImages.count @@ -205,7 +204,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { func hideViews() { galleryView.alpha = 0 bottomContainer.pickerButton.enabled = false - bottomContainer.imageWrapper.tapGestureRecognizer.enabled = false +// bottomContainer.imageWrapper.tapGestureRecognizer.enabled = false topView.flashButton.enabled = false topView.rotateCamera.enabled = false } @@ -215,7 +214,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { cameraController.initializeCamera() galleryView.alpha = 1 bottomContainer.pickerButton.enabled = true - bottomContainer.imageWrapper.tapGestureRecognizer.enabled = true + //bottomContainer.imageWrapper.tapGestureRecognizer.enabled = true topView.flashButton.enabled = true topView.rotateCamera.enabled = true } @@ -229,7 +228,6 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { } func imageSelected(array: NSMutableArray) { - bottomContainer.updateWrapperImages(galleryView.selectedImages) let title = galleryView.selectedImages.count != 0 ? self.configuration.doneButtonTitle : self.configuration.cancelButtonTitle bottomContainer.doneButton.setTitle(title, forState: .Normal) } From 622c719453dbd8a465675252bdc7ad604af7a3ec Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 09:14:01 +0200 Subject: [PATCH 16/26] Show images in correct order --- Source/BottomView/ImageStack.swift | 2 +- Source/BottomView/StackView.swift | 14 +++++--------- Source/PickerConfiguration.swift | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 56766bf9..3256a595 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -28,4 +28,4 @@ struct ImageStack { func containsImage(image: UIImage) -> Bool { return contains(images, image) } -} +} \ No newline at end of file diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 8266f102..748d17fa 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -15,7 +15,6 @@ class StackView: UIView { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor.blueColor() - println(views.count) views.map{ self.addSubview($0) } layoutSubviews() @@ -25,13 +24,9 @@ class StackView: UIView { override func layoutSubviews() { let step = -4 for (i, view) in enumerate(views) { - println("a") var side = i * step var frame = CGRect(origin: CGPoint(x: side, y: side), size: viewSize) view.frame = frame - view.backgroundColor = UIColor.redColor() - view.layer.borderColor = UIColor.blackColor().CGColor - view.layer.borderWidth = 1 } } @@ -42,10 +37,11 @@ class StackView: UIView { extension StackView: ImageStackDelegate { func imageStackDidReload() { - for (index, image) in enumerate(ImageStack.sharedStack.images) { - if index < 4 { + let photos = ImageStack.sharedStack.images + let size = min(photos.count - 1, 3) + let lastFour = photos.reverse()[0...size].reverse() + for (index, image) in enumerate(lastFour) { views[index].image = image - } } } -} +} \ No newline at end of file diff --git a/Source/PickerConfiguration.swift b/Source/PickerConfiguration.swift index ddb8ac07..564de0eb 100644 --- a/Source/PickerConfiguration.swift +++ b/Source/PickerConfiguration.swift @@ -24,4 +24,4 @@ public class PickerConfiguration { // MARK: Dimensions public var cellSpacing: CGFloat = 2 -} +} \ No newline at end of file From ab44a328e14c265d24b63921cb6c53038e1d1a4b Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 09:21:08 +0200 Subject: [PATCH 17/26] Delegate method to map --- Source/BottomView/StackView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 748d17fa..786fe7eb 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -40,8 +40,8 @@ extension StackView: ImageStackDelegate { let photos = ImageStack.sharedStack.images let size = min(photos.count - 1, 3) let lastFour = photos.reverse()[0...size].reverse() - for (index, image) in enumerate(lastFour) { - views[index].image = image - } + Array(map(enumerate(lastFour)) { (index, image) in + self.views[index].image = image + }) } } \ No newline at end of file From 070efcd780e1dbaf74228d3ba5b1430c9de506ce Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 09:31:51 +0200 Subject: [PATCH 18/26] Add array of views and gesture recognizer --- Source/BottomView/StackView.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 786fe7eb..c2ed735d 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -4,12 +4,25 @@ class StackView: UIView { var views: [UIImageView] = { var array = [UIImageView]() - for i in 1...4 { - array.append(UIImageView()) + for i in 0...3 { + let view = UIImageView() + view.layer.cornerRadius = 3 + view.layer.borderColor = UIColor(white: 1, alpha: 0.2).CGColor + view.layer.borderWidth = 1 + view.contentMode = .ScaleAspectFill + view.clipsToBounds = true +// view.addGestureRecognizer(self.tapGestureRecognizer) + array.append(view) } return array }() + lazy var tapGestureRecognizer: UITapGestureRecognizer = { + let gesture = UITapGestureRecognizer() + gesture.addTarget(self, action: "handleTapGestureRecognizer:") + + return gesture + }() lazy var viewSize: CGSize = CGSize(width: self.frame.width * 0.6, height: self.frame.height * 0.6) override init(frame: CGRect) { From e5121789d943833ae08c9ecacae87657ac5068c2 Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 09:54:58 +0200 Subject: [PATCH 19/26] Refactor delegate methods --- Source/BottomView/ImageStack.swift | 9 +++++---- Source/BottomView/StackView.swift | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index 3256a595..fe75ba11 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -1,7 +1,8 @@ import UIKit protocol ImageStackDelegate { - func imageStackDidReload() + func imageDidPush(image: UIImage) + func imageStackDidDrop(image: UIImage) } struct ImageStack { @@ -13,14 +14,14 @@ struct ImageStack { mutating func pushImage(image: UIImage) { images.append(image) - delegate?.imageStackDidReload() - println("Image pushed") + delegate?.imageDidPush(image) + println("Image push") println(images) } mutating func dropImage(image: UIImage) { images = images.filter() {$0 != image} - delegate?.imageStackDidReload() + delegate?.imageStackDidDrop(image) println("Image dropped") println(images) } diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index c2ed735d..255953c4 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -49,9 +49,22 @@ class StackView: UIView { } extension StackView: ImageStackDelegate { - func imageStackDidReload() { + func imageDidPush(image: UIImage) { +renderViews() + } + + func imageStackDidDrop(image: UIImage) { +renderViews() + } + + func renderViews() { let photos = ImageStack.sharedStack.images - let size = min(photos.count - 1, 3) + if photos.isEmpty { + return + } + //TODO: Find better way to limit value to bounds + var size = min(photos.count - 1, 3) + size = max(size, 0) let lastFour = photos.reverse()[0...size].reverse() Array(map(enumerate(lastFour)) { (index, image) in self.views[index].image = image From ff32539c13f9d2c3d1372ae39f086ed0f90ca186 Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 10:34:47 +0200 Subject: [PATCH 20/26] Refactor StackView --- Source/BottomView/StackView.swift | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 255953c4..66031f4c 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -11,7 +11,7 @@ class StackView: UIView { view.layer.borderWidth = 1 view.contentMode = .ScaleAspectFill view.clipsToBounds = true -// view.addGestureRecognizer(self.tapGestureRecognizer) + // view.addGestureRecognizer(self.tapGestureRecognizer) array.append(view) } return array @@ -27,11 +27,11 @@ class StackView: UIView { override init(frame: CGRect) { super.init(frame: frame) - backgroundColor = UIColor.blueColor() views.map{ self.addSubview($0) } layoutSubviews() ImageStack.sharedStack.delegate = self + renderViews() } override func layoutSubviews() { @@ -50,24 +50,26 @@ class StackView: UIView { extension StackView: ImageStackDelegate { func imageDidPush(image: UIImage) { -renderViews() + renderViews() } func imageStackDidDrop(image: UIImage) { -renderViews() + renderViews() } func renderViews() { let photos = ImageStack.sharedStack.images - if photos.isEmpty { - return - } //TODO: Find better way to limit value to bounds var size = min(photos.count - 1, 3) - size = max(size, 0) - let lastFour = photos.reverse()[0...size].reverse() - Array(map(enumerate(lastFour)) { (index, image) in - self.views[index].image = image - }) + + for (index, view) in enumerate(views.reverse()) { + if index <= size { + view.image = photos.reverse()[index] + view.alpha = 1 + } else { + view.image = nil + view.alpha = 0 + } + } } } \ No newline at end of file From ca040fa4059b5286f962e808444979226c640e7e Mon Sep 17 00:00:00 2001 From: Richard Topchii Date: Tue, 11 Aug 2015 10:48:31 +0200 Subject: [PATCH 21/26] Refactor stack view --- Source/BottomView/StackView.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 66031f4c..f8f0c3c6 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -1,7 +1,13 @@ import UIKit +//protocol ImageWrapperDelegate { +// func imageWrapperDidPress() +//} + class StackView: UIView { + var delegate: ImageWrapperDelegate? + var views: [UIImageView] = { var array = [UIImageView]() for i in 0...3 { @@ -11,7 +17,6 @@ class StackView: UIView { view.layer.borderWidth = 1 view.contentMode = .ScaleAspectFill view.clipsToBounds = true - // view.addGestureRecognizer(self.tapGestureRecognizer) array.append(view) } return array @@ -23,12 +28,14 @@ class StackView: UIView { return gesture }() + lazy var viewSize: CGSize = CGSize(width: self.frame.width * 0.6, height: self.frame.height * 0.6) override init(frame: CGRect) { super.init(frame: frame) views.map{ self.addSubview($0) } - +// views.map{ $0.addGestureRecognizer(self.tapGestureRecognizer) } + self.addGestureRecognizer(tapGestureRecognizer) layoutSubviews() ImageStack.sharedStack.delegate = self renderViews() @@ -43,6 +50,11 @@ class StackView: UIView { } } + func handleTapGestureRecognizer(gesture: UITapGestureRecognizer) { + println("asdas") + delegate?.imageWrapperDidPress() + } + required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } From a8ef893796f245c0df445a11d3d079b895356b23 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 11:17:13 +0200 Subject: [PATCH 22/26] Remove debugging code from ImageStack --- Source/BottomView/ImageStack.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/BottomView/ImageStack.swift b/Source/BottomView/ImageStack.swift index fe75ba11..d781ce73 100644 --- a/Source/BottomView/ImageStack.swift +++ b/Source/BottomView/ImageStack.swift @@ -15,18 +15,14 @@ struct ImageStack { mutating func pushImage(image: UIImage) { images.append(image) delegate?.imageDidPush(image) - println("Image push") - println(images) } mutating func dropImage(image: UIImage) { images = images.filter() {$0 != image} delegate?.imageStackDidDrop(image) - println("Image dropped") - println(images) } func containsImage(image: UIImage) -> Bool { return contains(images, image) } -} \ No newline at end of file +} From 75552f790e2c9234fe65187c7982d6ebca55e0a8 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 11:17:29 +0200 Subject: [PATCH 23/26] Fully remove ImageWrapper --- Source/BottomView/ImageWrapper.swift | 126 --------------------------- 1 file changed, 126 deletions(-) delete mode 100644 Source/BottomView/ImageWrapper.swift diff --git a/Source/BottomView/ImageWrapper.swift b/Source/BottomView/ImageWrapper.swift deleted file mode 100644 index 5d5e4381..00000000 --- a/Source/BottomView/ImageWrapper.swift +++ /dev/null @@ -1,126 +0,0 @@ -import UIKit - -protocol ImageWrapperDelegate { - - func imageWrapperDidPress() -} - -class ImageWrapper: UIView { - - struct Dimensions { - static let imageSize: CGFloat = 52 - } - - lazy var firstImageView: UIImageView = { - let imageView = UIImageView() - return imageView - }() - - lazy var secondImageView: UIImageView = { - let imageView = UIImageView() - imageView.alpha = 0 - - return imageView - }() - - lazy var thirdImageView: UIImageView = { - let imageView = UIImageView() - imageView.alpha = 0 - - return imageView - }() - - lazy var fourthImageView: UIImageView = { - let imageView = UIImageView() - imageView.alpha = 0 - - return imageView - }() - - lazy var tapGestureRecognizer: UITapGestureRecognizer = { - let gesture = UITapGestureRecognizer() - gesture.addTarget(self, action: "handleTapGestureRecognizer:") - - return gesture - }() - - var delegate: ImageWrapperDelegate? - - // MARK: - Initializers - - override init(frame: CGRect) { - super.init(frame: frame) - - setupConfigureImageViews() - setupConstraints() - } - - required init(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - // MARK: - Configuration - - func setupConfigureImageViews() { - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.layer.cornerRadius = 3 } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.layer.borderColor = UIColor(white: 1, alpha: 0.2).CGColor } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.layer.borderWidth = 1 } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.contentMode = .ScaleAspectFill } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.clipsToBounds = true } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.setTranslatesAutoresizingMaskIntoConstraints(false) } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { self.addSubview($0) } - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { $0.addGestureRecognizer(self.tapGestureRecognizer) } - } - - // MARK: - Autolayout - - func setupConstraints() { - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { self.addConstraint(NSLayoutConstraint(item: $0, attribute: .Height, - relatedBy: .Equal, toItem: self, attribute: .Height, - multiplier: 1, constant: 0)) - } - - [firstImageView, secondImageView, thirdImageView, fourthImageView].map { self.addConstraint(NSLayoutConstraint(item: $0, attribute: .Width, - relatedBy: .Equal, toItem: self, attribute: .Width, - multiplier: 1, constant: 0)) - } - - addConstraint(NSLayoutConstraint(item: firstImageView, attribute: .CenterX, - relatedBy: .Equal, toItem: self, attribute: .CenterX, - multiplier: 1, constant: 0)) - - addConstraint(NSLayoutConstraint(item: firstImageView, attribute: .CenterY, - relatedBy: .Equal, toItem: self, attribute: .CenterY, - multiplier: 1, constant: 0)) - - addConstraint(NSLayoutConstraint(item: secondImageView, attribute: .CenterY, - relatedBy: .Equal, toItem: self, attribute: .CenterY, - multiplier: 1, constant: -2.5)) - - addConstraint(NSLayoutConstraint(item: secondImageView, attribute: .CenterX, - relatedBy: .Equal, toItem: self, attribute: .CenterX, - multiplier: 1, constant: -2.5)) - - addConstraint(NSLayoutConstraint(item: thirdImageView, attribute: .CenterY, - relatedBy: .Equal, toItem: self, attribute: .CenterY, - multiplier: 1, constant: -5)) - - addConstraint(NSLayoutConstraint(item: thirdImageView, attribute: .CenterX, - relatedBy: .Equal, toItem: self, attribute: .CenterX, - multiplier: 1, constant: -5)) - - addConstraint(NSLayoutConstraint(item: fourthImageView, attribute: .CenterY, - relatedBy: .Equal, toItem: self, attribute: .CenterY, - multiplier: 1, constant: -7.5)) - - addConstraint(NSLayoutConstraint(item: fourthImageView, attribute: .CenterX, - relatedBy: .Equal, toItem: self, attribute: .CenterX, - multiplier: 1, constant: -7.5)) - } - - // MARK: - Actions - - func handleTapGestureRecognizer(gesture: UITapGestureRecognizer) { - delegate?.imageWrapperDidPress() - } -} From 1afb0d3cb2a5b309d0d6a07543c6dfe603ebbe60 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 11:18:19 +0200 Subject: [PATCH 24/26] Refactor variable names to StackView --- Source/BottomView/BottomContainerView.swift | 16 ++++++++-------- Source/BottomView/StackView.swift | 14 ++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index f001703d..faaa14e7 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -40,7 +40,7 @@ class BottomContainerView: UIView { return button }() - lazy var imageWrapper: StackView = { + lazy var stackView: StackView = { let view = StackView(frame: CGRect(x: 0, y: 0, width: 80, height: 80)) view.setTranslatesAutoresizingMaskIntoConstraints(false) @@ -67,7 +67,7 @@ class BottomContainerView: UIView { override init(frame: CGRect) { super.init(frame: frame) - [borderPickerButton, pickerButton, doneButton, imageWrapper, topSeparator].map { self.addSubview($0) } + [borderPickerButton, pickerButton, doneButton, stackView, topSeparator].map { self.addSubview($0) } backgroundColor = self.configuration.backgroundColor setupConstraints() @@ -119,19 +119,19 @@ class BottomContainerView: UIView { relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1, constant: -(UIScreen.mainScreen().bounds.width - (ButtonPicker.Dimensions.buttonBorderSize + UIScreen.mainScreen().bounds.width)/2)/2)) - addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .Width, + addConstraint(NSLayoutConstraint(item: stackView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, - multiplier: 1, constant: ImageWrapper.Dimensions.imageSize)) + multiplier: 1, constant: StackView.Dimensions.imageSize)) - addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .Height, + addConstraint(NSLayoutConstraint(item: stackView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, - multiplier: 1, constant: ImageWrapper.Dimensions.imageSize)) + multiplier: 1, constant: StackView.Dimensions.imageSize)) - addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .CenterY, + addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0)) - addConstraint(NSLayoutConstraint(item: imageWrapper, attribute: .CenterX, + addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1, constant: UIScreen.mainScreen().bounds.width/4 - ButtonPicker.Dimensions.buttonBorderSize/4)) diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index f8f0c3c6..534cc65e 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -1,11 +1,15 @@ import UIKit -//protocol ImageWrapperDelegate { -// func imageWrapperDidPress() -//} +protocol ImageWrapperDelegate { + func imageWrapperDidPress() +} class StackView: UIView { + struct Dimensions { + static let imageSize: CGFloat = 52 + } + var delegate: ImageWrapperDelegate? var views: [UIImageView] = { @@ -34,7 +38,6 @@ class StackView: UIView { override init(frame: CGRect) { super.init(frame: frame) views.map{ self.addSubview($0) } -// views.map{ $0.addGestureRecognizer(self.tapGestureRecognizer) } self.addGestureRecognizer(tapGestureRecognizer) layoutSubviews() ImageStack.sharedStack.delegate = self @@ -51,7 +54,6 @@ class StackView: UIView { } func handleTapGestureRecognizer(gesture: UITapGestureRecognizer) { - println("asdas") delegate?.imageWrapperDidPress() } @@ -84,4 +86,4 @@ extension StackView: ImageStackDelegate { } } } -} \ No newline at end of file +} From 62104dded4a7caedd6820a6b198148616b8bdb2a Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 11:29:20 +0200 Subject: [PATCH 25/26] Fully refactor remains of Wrapper --- Source/BottomView/BottomContainerView.swift | 10 +++++----- Source/BottomView/StackView.swift | 8 ++++---- Source/ImagePickerController.swift | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/BottomView/BottomContainerView.swift b/Source/BottomView/BottomContainerView.swift index faaa14e7..d308c238 100644 --- a/Source/BottomView/BottomContainerView.swift +++ b/Source/BottomView/BottomContainerView.swift @@ -5,7 +5,7 @@ protocol BottomContainerViewDelegate { func pickerButtonDidPress() func doneButtonDidPress() func cancelButtonDidPress() - func imageWrapperDidPress() + func stackViewDidPress() } class BottomContainerView: UIView { @@ -178,11 +178,11 @@ extension BottomContainerView: ButtonPickerDelegate { } } -// MARK: - ImageWrapperDelegate methods +// MARK: - StackViewDelegate methods -extension BottomContainerView: ImageWrapperDelegate { +extension BottomContainerView: StackViewDelegate { - func imageWrapperDidPress() { - delegate?.imageWrapperDidPress() + func stackViewDidPress() { + delegate?.stackViewDidPress() } } diff --git a/Source/BottomView/StackView.swift b/Source/BottomView/StackView.swift index 534cc65e..72a42347 100644 --- a/Source/BottomView/StackView.swift +++ b/Source/BottomView/StackView.swift @@ -1,7 +1,7 @@ import UIKit -protocol ImageWrapperDelegate { - func imageWrapperDidPress() +protocol StackViewDelegate { + func stackViewDidPress() } class StackView: UIView { @@ -10,7 +10,7 @@ class StackView: UIView { static let imageSize: CGFloat = 52 } - var delegate: ImageWrapperDelegate? + var delegate: StackViewDelegate? var views: [UIImageView] = { var array = [UIImageView]() @@ -54,7 +54,7 @@ class StackView: UIView { } func handleTapGestureRecognizer(gesture: UITapGestureRecognizer) { - delegate?.imageWrapperDidPress() + delegate?.stackViewDidPress() } required init(coder aDecoder: NSCoder) { diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index 92cea454..f9109179 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -3,7 +3,7 @@ import UIKit @objc public protocol ImagePickerDelegate { - optional func wrapperDidPress(images: [UIImage]) + optional func stackViewDidPress(images: [UIImage]) optional func doneButtonDidPress(images: [UIImage]) optional func cancelButtonDidPress() } @@ -152,8 +152,8 @@ extension ImagePickerController: BottomContainerViewDelegate { delegate?.cancelButtonDidPress?() } - func imageWrapperDidPress() { - delegate?.wrapperDidPress?(galleryView.selectedImages.mutableCopy() as! [UIImage]) + func stackViewDidPress() { + delegate?.stackViewDidPress?(galleryView.selectedImages.mutableCopy() as! [UIImage]) } } @@ -204,7 +204,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { func hideViews() { galleryView.alpha = 0 bottomContainer.pickerButton.enabled = false -// bottomContainer.imageWrapper.tapGestureRecognizer.enabled = false + bottomContainer.stackView.tapGestureRecognizer.enabled = false topView.flashButton.enabled = false topView.rotateCamera.enabled = false } @@ -214,7 +214,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate { cameraController.initializeCamera() galleryView.alpha = 1 bottomContainer.pickerButton.enabled = true - //bottomContainer.imageWrapper.tapGestureRecognizer.enabled = true + bottomContainer.stackView.tapGestureRecognizer.enabled = true topView.flashButton.enabled = true topView.rotateCamera.enabled = true } From 5ea7743d12d3ec5f8d2b6df30ae732b75101fdbb Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 11:33:23 +0200 Subject: [PATCH 26/26] Remove shared scheme --- .../xcschemes/ImagePickerDemo.xcscheme | 112 ------------------ 1 file changed, 112 deletions(-) delete mode 100644 Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme diff --git a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme b/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme deleted file mode 100644 index 106780d4..00000000 --- a/Demo/ImagePickerDemo/ImagePickerDemo.xcodeproj/xcshareddata/xcschemes/ImagePickerDemo.xcscheme +++ /dev/null @@ -1,112 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -