|
|
@ -9,13 +9,18 @@ |
|
|
|
import AlamofireImage |
|
|
|
import UIKit |
|
|
|
|
|
|
|
class AttachmentManager { |
|
|
|
class AttachmentsManager { |
|
|
|
static func setupAttachmentsView(_ view: AttachmentsView, withAttachments attachments: NSOrderedSet?) { |
|
|
|
guard let attachments = attachments, attachments.count > 0 else { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let placeholderImage = UIImage(named: "Help") |
|
|
|
let halfWidth = (view.frame.width / 2) - 2 |
|
|
|
|
|
|
|
for subview in view.subviews as [UIView] { |
|
|
|
subview.removeFromSuperview() |
|
|
|
} |
|
|
|
|
|
|
|
switch attachments.count { |
|
|
|
case 0: |
|
|
@ -41,10 +46,10 @@ class AttachmentManager { |
|
|
|
view.addConstraint(getTrailingConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getTopConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getBottomConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getWidthConstraint(view: imageView, width: view.frame.width)) |
|
|
|
view.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width)) |
|
|
|
imageView.addConstraint(getWidthConstraint(view: imageView, width: view.frame.width)) |
|
|
|
imageView.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width)) |
|
|
|
case 2: |
|
|
|
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: (view.frame.width / 2) - 2, height: view.frame.width)) |
|
|
|
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: view.frame.width)) |
|
|
|
|
|
|
|
let firstImageView = UIImageView() |
|
|
|
let secondImageView = UIImageView() |
|
|
@ -68,15 +73,19 @@ class AttachmentManager { |
|
|
|
view.addSubview(firstImageView) |
|
|
|
view.addSubview(secondImageView) |
|
|
|
|
|
|
|
firstImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
secondImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
[firstImageView, secondImageView].forEach { imageView in |
|
|
|
view.addConstraint(getLeadingConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getTrailingConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getTopConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getBottomConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width)) |
|
|
|
view.addConstraint(getWidthConstraint(view: imageView, width: (view.frame.width / 2) - 2)) |
|
|
|
imageView.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width)) |
|
|
|
imageView.addConstraint(getWidthConstraint(view: imageView, width: halfWidth)) |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
let betweenConstraint = NSLayoutConstraint( |
|
|
|
item: firstImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.trailing, |
|
|
@ -88,9 +97,8 @@ class AttachmentManager { |
|
|
|
) |
|
|
|
|
|
|
|
view.addConstraint(betweenConstraint) |
|
|
|
*/ |
|
|
|
case 3: |
|
|
|
let halfWidth = (view.frame.width / 2) - 2 |
|
|
|
|
|
|
|
let primaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: view.frame.width)) |
|
|
|
let secondaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth)) |
|
|
|
|
|
|
@ -124,55 +132,25 @@ class AttachmentManager { |
|
|
|
view.addSubview(secondImageView) |
|
|
|
view.addSubview(thirdImageView) |
|
|
|
|
|
|
|
firstImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
secondImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
thirdImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
view.addConstraint(getLeadingConstraint(from: firstImageView, to: view)) |
|
|
|
view.addConstraint(getTopConstraint(from: firstImageView, to: view)) |
|
|
|
view.addConstraint(getBottomConstraint(from: firstImageView, to: view)) |
|
|
|
view.addConstraint(getHeightConstraint(view: firstImageView, height: view.frame.width)) |
|
|
|
view.addConstraint(getWidthConstraint(view: firstImageView, width: halfWidth)) |
|
|
|
firstImageView.addConstraint(getHeightConstraint(view: firstImageView, height: view.frame.width)) |
|
|
|
firstImageView.addConstraint(getWidthConstraint(view: firstImageView, width: halfWidth)) |
|
|
|
|
|
|
|
view.addConstraint(getTopConstraint(from: secondImageView, to: view)) |
|
|
|
view.addConstraint(getBottomConstraint(from: thirdImageView, to: view)) |
|
|
|
|
|
|
|
[secondImageView, thirdImageView].forEach { imageView in |
|
|
|
view.addConstraint(getTrailingConstraint(from: imageView, to: view)) |
|
|
|
view.addConstraint(getHeightConstraint(view: imageView, height: halfWidth)) |
|
|
|
view.addConstraint(getWidthConstraint(view: imageView, width: halfWidth)) |
|
|
|
imageView.addConstraint(getHeightConstraint(view: imageView, height: halfWidth)) |
|
|
|
imageView.addConstraint(getWidthConstraint(view: imageView, width: halfWidth)) |
|
|
|
} |
|
|
|
|
|
|
|
let firstSecondConstraint = NSLayoutConstraint( |
|
|
|
item: firstImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.trailing, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: secondImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.leading, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
let firstThirdConstraint = NSLayoutConstraint( |
|
|
|
item: firstImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.trailing, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: thirdImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.leading, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
let secondThirdConstraint = NSLayoutConstraint( |
|
|
|
item: secondImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.bottom, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: thirdImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.top, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
view.addConstraints([firstSecondConstraint, firstThirdConstraint, secondThirdConstraint]) |
|
|
|
default: |
|
|
|
let halfWidth = (view.frame.width / 2) - 2 |
|
|
|
|
|
|
|
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth)) |
|
|
|
|
|
|
|
let firstImageView = UIImageView() |
|
|
@ -213,9 +191,14 @@ class AttachmentManager { |
|
|
|
view.addSubview(thirdImageView) |
|
|
|
view.addSubview(fourthImageView) |
|
|
|
|
|
|
|
firstImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
secondImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
thirdImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
fourthImageView.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
[firstImageView, secondImageView, thirdImageView, fourthImageView].forEach { imageView in |
|
|
|
view.addConstraint(getHeightConstraint(view: imageView, height: halfWidth)) |
|
|
|
view.addConstraint(getWidthConstraint(view: imageView, width: halfWidth)) |
|
|
|
imageView.addConstraint(getHeightConstraint(view: imageView, height: halfWidth)) |
|
|
|
imageView.addConstraint(getWidthConstraint(view: imageView, width: halfWidth)) |
|
|
|
} |
|
|
|
|
|
|
|
[firstImageView, secondImageView].forEach { imageView in |
|
|
@ -233,53 +216,6 @@ class AttachmentManager { |
|
|
|
[secondImageView, fourthImageView].forEach { imageView in |
|
|
|
view.addConstraint(getTrailingConstraint(from: imageView, to: view)) |
|
|
|
} |
|
|
|
|
|
|
|
let firstBetweenConstraint = NSLayoutConstraint( |
|
|
|
item: firstImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.trailing, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: secondImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.leading, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
let secondBetweenConstraint = NSLayoutConstraint( |
|
|
|
item: secondImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.bottom, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: fourthImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.top, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
let thirdBetweenConstraint = NSLayoutConstraint( |
|
|
|
item: fourthImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.leading, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: thirdImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.trailing, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
let fourthBetweenConstraint = NSLayoutConstraint( |
|
|
|
item: thirdImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.top, |
|
|
|
relatedBy: NSLayoutConstraint.Relation.equal, |
|
|
|
toItem: firstImageView, |
|
|
|
attribute: NSLayoutConstraint.Attribute.bottom, |
|
|
|
multiplier: 1, |
|
|
|
constant: 4 |
|
|
|
) |
|
|
|
|
|
|
|
view.addConstraints([ |
|
|
|
firstBetweenConstraint, |
|
|
|
secondBetweenConstraint, |
|
|
|
thirdBetweenConstraint, |
|
|
|
fourthBetweenConstraint, |
|
|
|
]) |
|
|
|
} |
|
|
|
} |
|
|
|
|