From 094bdf91dddf0fff069a971a5fc8083678c533f3 Mon Sep 17 00:00:00 2001 From: richardoti Date: Tue, 11 Aug 2015 03:56:41 +0200 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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) }