Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements/refactoring matching desings #18

Merged
merged 33 commits into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e789169
Changed the main colors
RamonGilabert Aug 27, 2015
dd0618f
Refactored constraints
RamonGilabert Aug 27, 2015
1b9c80d
Moves constraints and add class protocol
RamonGilabert Aug 27, 2015
90d9781
Adds weak delegates everywhere
RamonGilabert Aug 27, 2015
c345ff8
Changes some variables
RamonGilabert Aug 27, 2015
c4f7c6c
Changes even more constants
RamonGilabert Aug 27, 2015
8f9ce7b
Changed for a for loop
RamonGilabert Aug 27, 2015
0338e90
Changed map for a for loop
RamonGilabert Aug 27, 2015
77b8822
Adds another for loop of refactoring
RamonGilabert Aug 27, 2015
cbc20be
Dropped [unowned self]
RamonGilabert Aug 27, 2015
b51a54d
Adds a bunch of small fixes
RamonGilabert Aug 27, 2015
1a637da
Adds a new class with all the autolayout
RamonGilabert Aug 27, 2015
be30e88
Adds a bit of configuration
RamonGilabert Aug 27, 2015
1cb4e8d
Moving autolayout to an extension
RamonGilabert Aug 27, 2015
36b8d95
Changed team to Hyper and changed order of things
RamonGilabert Aug 27, 2015
28e9cd4
Using constraints now for the camera preview
RamonGilabert Aug 27, 2015
fa0d99e
Changing constraints
RamonGilabert Aug 27, 2015
fdab95f
Add the correct shadow
RamonGilabert Aug 27, 2015
33a8c0f
Changing colors here and there
RamonGilabert Aug 27, 2015
79b81ec
Refactored the pan gesture did change method
RamonGilabert Aug 27, 2015
03b3b6e
Adds always the same offset
RamonGilabert Aug 28, 2015
7e6df3c
Finish pan refactoring
RamonGilabert Aug 28, 2015
0bc8a66
Changes constants and adds a new one
RamonGilabert Aug 28, 2015
413e48a
Smalls refactor
RamonGilabert Aug 28, 2015
ef2ee2d
More refactor
RamonGilabert Aug 28, 2015
6a86846
Moving constraints away
RamonGilabert Aug 28, 2015
24bd175
Change name of the file
RamonGilabert Aug 28, 2015
f915768
Delete space
RamonGilabert Aug 28, 2015
0356bb8
Adds the last animation check
RamonGilabert Aug 28, 2015
b7d0af2
Improves animation when expanding the gallery view
RamonGilabert Aug 28, 2015
0907e77
Renames the file again
RamonGilabert Aug 28, 2015
55d0c2b
Deletes the @objc optional protocols
RamonGilabert Aug 28, 2015
7e2394c
Adds unowned self
RamonGilabert Aug 28, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
TargetAttributes = {
29D699D81B70ABFC0021FA73 = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = SGM42FXP52;
DevelopmentTeam = XVAH95CHDC;
};
29D699ED1B70ABFC0021FA73 = {
CreatedOnToolsVersion = 6.4;
Expand Down
91 changes: 10 additions & 81 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

protocol BottomContainerViewDelegate {
protocol BottomContainerViewDelegate: class {

func pickerButtonDidPress()
func doneButtonDidPress()
Expand All @@ -10,10 +10,9 @@ protocol BottomContainerViewDelegate {

class BottomContainerView: UIView {

lazy var pickerButton: ButtonPicker = {
lazy var pickerButton: ButtonPicker = { [unowned self] in
let pickerButton = ButtonPicker()
pickerButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
pickerButton.setTranslatesAutoresizingMaskIntoConstraints(false)
pickerButton.delegate = self

return pickerButton
Expand All @@ -25,7 +24,6 @@ class BottomContainerView: UIView {
view.layer.borderColor = UIColor.whiteColor().CGColor
view.layer.borderWidth = ButtonPicker.Dimensions.borderWidth
view.layer.cornerRadius = ButtonPicker.Dimensions.buttonBorderSize / 2
view.setTranslatesAutoresizingMaskIntoConstraints(false)

return view
}()
Expand All @@ -35,15 +33,12 @@ class BottomContainerView: UIView {
button.setTitle(self.configuration.cancelButtonTitle, forState: .Normal)
button.titleLabel!.font = self.configuration.doneButton
button.addTarget(self, action: "doneButtonDidPress:", forControlEvents: .TouchUpInside)
button.setTranslatesAutoresizingMaskIntoConstraints(false)

return button
}()

lazy var stackView: ImageStackView = {
let view = ImageStackView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
view.setTranslatesAutoresizingMaskIntoConstraints(false)

return view
}()
lazy var configuration: PickerConfiguration = {
Expand All @@ -53,28 +48,31 @@ class BottomContainerView: UIView {

lazy var topSeparator: UIView = { [unowned self] in
let view = UIView()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.backgroundColor = self.configuration.backgroundColor

return view
}()

lazy var tapGestureRecognizer: UITapGestureRecognizer = {
lazy var tapGestureRecognizer: UITapGestureRecognizer = { [unowned self] in
let gesture = UITapGestureRecognizer()
gesture.addTarget(self, action: "handleTapGestureRecognizer:")

return gesture
}()

var delegate: BottomContainerViewDelegate?
weak var delegate: BottomContainerViewDelegate?
var pastCount = 0

// MARK: Initializers

override init(frame: CGRect) {
super.init(frame: frame)

[borderPickerButton, pickerButton, doneButton, stackView, topSeparator].map { self.addSubview($0) }
for view in [borderPickerButton, pickerButton, doneButton, stackView, topSeparator] {
addSubview(view)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
}

backgroundColor = configuration.backgroundColor
stackView.addGestureRecognizer(tapGestureRecognizer)

Expand All @@ -85,75 +83,6 @@ class BottomContainerView: UIView {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Autolayout

func setupConstraints() {
let attributesBorder: [NSLayoutAttribute] = [.CenterX, .CenterY]
let attributesSeparator: [NSLayoutAttribute] = [.Width, .Left, .Top]

attributesBorder.map {
self.addConstraint(NSLayoutConstraint(item: self.pickerButton, attribute: $0,
relatedBy: .Equal, toItem: self, attribute: $0,
multiplier: 1, constant: 0))
}

addConstraint(NSLayoutConstraint(item: pickerButton, attribute: .Width,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ButtonPicker.Dimensions.buttonSize))

addConstraint(NSLayoutConstraint(item: pickerButton, attribute: .Height,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ButtonPicker.Dimensions.buttonSize))

attributesBorder.map {
self.addConstraint(NSLayoutConstraint(item: self.borderPickerButton, attribute: $0,
relatedBy: .Equal, toItem: self, attribute: $0,
multiplier: 1, constant: 0))
}

addConstraint(NSLayoutConstraint(item: borderPickerButton, attribute: .Width,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ButtonPicker.Dimensions.buttonBorderSize))

addConstraint(NSLayoutConstraint(item: borderPickerButton, attribute: .Height,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ButtonPicker.Dimensions.buttonBorderSize))

addConstraint(NSLayoutConstraint(item: doneButton, attribute: .CenterY,
relatedBy: .Equal, toItem: self, attribute: .CenterY,
multiplier: 1, constant: 0))

addConstraint(NSLayoutConstraint(item: doneButton, attribute: .CenterX,
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: stackView, attribute: .Width,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ImageStackView.Dimensions.imageSize))

addConstraint(NSLayoutConstraint(item: stackView, attribute: .Height,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: ImageStackView.Dimensions.imageSize))

addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterY,
relatedBy: .Equal, toItem: self, attribute: .CenterY,
multiplier: 1, constant: 0))

addConstraint(NSLayoutConstraint(item: stackView, attribute: .CenterX,
relatedBy: .Equal, toItem: self, attribute: .Left,
multiplier: 1, constant: UIScreen.mainScreen().bounds.width/4 - ButtonPicker.Dimensions.buttonBorderSize/4))

attributesSeparator.map {
self.addConstraint(NSLayoutConstraint(item: self.topSeparator, attribute: $0,
relatedBy: .Equal, toItem: self, attribute: $0,
multiplier: 1, constant: 0))
}

addConstraint(NSLayoutConstraint(item: topSeparator, attribute: .Height,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: 1))
}

// MARK: - Action methods

func doneButtonDidPress(button: UIButton) {
Expand All @@ -171,7 +100,7 @@ class BottomContainerView: UIView {
private func animateImageView(imageView: UIImageView) {
imageView.transform = CGAffineTransformMakeScale(0, 0)

UIView.animateWithDuration(0.3, animations: { [unowned self] in
UIView.animateWithDuration(0.3, animations: {
imageView.transform = CGAffineTransformMakeScale(1.05, 1.05)
}, completion: { _ in
UIView.animateWithDuration(0.2, animations: { _ in
Expand Down
5 changes: 2 additions & 3 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class ButtonPicker: UIButton {

struct Dimensions {
static let borderWidth: CGFloat = 2
static let buttonSize: CGFloat = 72
static let buttonBorderSize: CGFloat = 82
static let buttonSize: CGFloat = 58
static let buttonBorderSize: CGFloat = 68
}

lazy var numberLabel: UILabel = { [unowned self] in
let label = UILabel()
label.text = ""
label.setTranslatesAutoresizingMaskIntoConstraints(false)
label.font = self.configuration.numberLabelFont

Expand Down
6 changes: 3 additions & 3 deletions Source/BottomView/ImageStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import UIKit
public class ImageStack {

public struct Notifications {
public static let imageDidPush = "imageDidPush:"
public static let imageDidDrop = "imageDidDrop:"
public static let stackDidReload = "stackDidReload:"
public static let imageDidPush = "imageDidPush"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. This needs to be checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a notification name, not a method. The name of the notification is imageDidPush, not imageDidPush:.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I did few tests to check that it works correctly. Seems that I've just copied selector.

public static let imageDidDrop = "imageDidDrop"
public static let stackDidReload = "stackDidReload"
public static let imageKey = "image"
}

Expand Down
18 changes: 12 additions & 6 deletions Source/BottomView/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ protocol ImageStackViewDelegate: class {
class ImageStackView: UIView {

struct Dimensions {
static let imageSize: CGFloat = 70
static let imageSize: CGFloat = 58
}

weak var delegate: ImageStackViewDelegate?
Expand All @@ -17,7 +17,7 @@ class ImageStackView: UIView {
for i in 0...3 {
let view = UIImageView()
view.layer.cornerRadius = 3
view.layer.borderColor = UIColor(white: 1, alpha: 0.2).CGColor
view.layer.borderColor = UIColor.whiteColor().CGColor
view.layer.borderWidth = 1
view.contentMode = .ScaleAspectFill
view.clipsToBounds = true
Expand All @@ -27,18 +27,27 @@ class ImageStackView: UIView {
return array
}()

// MARK: - Initializers

override init(frame: CGRect) {
super.init(frame: frame)

subscribe()
views.map { self.addSubview($0) }
views[0].alpha = 1
layoutSubviews()
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}

// MARK: - Helpers

func subscribe() {
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "imageDidPush:",
Expand Down Expand Up @@ -72,13 +81,10 @@ class ImageStackView: UIView {
view.frame = frame
}
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension ImageStackView {

func imageDidPush(notification: NSNotification) {

//TODO indexOf in swift 2
Expand Down
4 changes: 2 additions & 2 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import AVFoundation
import AssetsLibrary

protocol CameraViewDelegate {
protocol CameraViewDelegate: class {

func handleFlashButton(hide: Bool)
func imageToLibrary(image: UIImage)
Expand Down Expand Up @@ -46,7 +46,7 @@ class CameraView: UIViewController {
var captureDevice: AVCaptureDevice?
var capturedDevices: NSMutableArray?
var previewLayer: AVCaptureVideoPreviewLayer?
var delegate: CameraViewDelegate?
weak var delegate: CameraViewDelegate?
var stillImageOutput: AVCaptureStillImageOutput?
var animationTimer: NSTimer?

Expand Down
Loading