on master help sign in
Basic animations are now working.
0cde988ilyakooo0
Melk/CardView.swift+9−4
@@ -16,7 +16,7 @@ class CardView: UIView {
16 update()
16 update()
17 }
17 }
18 }
18 }
19− var width: CGFloat = 300 {
19+ var minWidth: CGFloat = 300 {
20 didSet {
20 didSet {
21 update()
21 update()
22 }
22 }
@@ -84,11 +84,15 @@ class CardView: UIView {
84 largeStack.addArrangedSubview(.spacer(vPadding1))
84 largeStack.addArrangedSubview(.spacer(vPadding1))
85
85
86
86
87+ let width = max(minWidth - 2 * padding.x, userView.frame.width)
88+
89+
87 let photoView = CollectionView()
90 let photoView = CollectionView()
88 photoView.alignment = .top
91 photoView.alignment = .top
89 photoView.horizontalPadding = 8
92 photoView.horizontalPadding = 8
90 photoView.verticalPadding = 8
93 photoView.verticalPadding = 8
91 photoView.padding = CGPoint.zero
94 photoView.padding = CGPoint.zero
95+ photoView.maxWidth = width
92 var maxPhotoDim: CGFloat = 150
96 var maxPhotoDim: CGFloat = 150
93 if let attachments = post?.attachments {
97 if let attachments = post?.attachments {
94 for attachment in attachments {
98 for attachment in attachments {
@@ -98,6 +102,7 @@ class CardView: UIView {
98 if var pWidth = photo.width.value >>> {CGFloat($0)},
102 if var pWidth = photo.width.value >>> {CGFloat($0)},
99 var pHeight = photo.height.value >>> {CGFloat($0)} {
103 var pHeight = photo.height.value >>> {CGFloat($0)} {
100 let photoV = UIImageView()
104 let photoV = UIImageView()
105+ photoV.layer.minificationFilter = kCAFilterTrilinear
101 photo.image?.load(into: photoV)
106 photo.image?.load(into: photoV)
102 var k: CGFloat!
107 var k: CGFloat!
103 if pWidth > pHeight {
108 if pWidth > pHeight {
@@ -123,7 +128,7 @@ class CardView: UIView {
123 textHeight -= padding.y + vPadding1 + userView.frame.height
128 textHeight -= padding.y + vPadding1 + userView.frame.height
124 if let count = post?.attachments.count{
129 if let count = post?.attachments.count{
125 if count > 0 {
130 if count > 0 {
126− textHeight -= vPadding2 + photoView.frame.height
131+ textHeight -= vPadding2 + photoView.frame.height + padding.y
127 }
132 }
128 }
133 }
129 print(textHeight)
134 print(textHeight)
@@ -132,7 +137,7 @@ class CardView: UIView {
132
137
133 let body = UILabel()
138 let body = UILabel()
134 body.numberOfLines = 0
139 body.numberOfLines = 0
135− let bodyWidth: Double = Double(width - padding.x * 2)
140+ let bodyWidth: Double = Double(width)
136 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
141 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
137 body.text = post?.body
142 body.text = post?.body
138 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
143 let size = body.textRect(forBounds: CGRect(x: 0, y: 0, width: bodyWidth, height: Double.infinity), limitedToNumberOfLines: 0).size
@@ -148,7 +153,7 @@ class CardView: UIView {
148 }
153 }
149 }
154 }
150
155
151− frame.size = CGSize(width: width, height: height)
156+ frame.size = CGSize(width: width + padding.x * 2, height: height)
152
157
153 }
158 }
154}
159}
Melk/CollectionView.swift+3−1
@@ -94,7 +94,9 @@ class CollectionView: UIView {
94 }
94 }
95 }
95 }
96 lastStack.layoutIfNeeded()
96 lastStack.layoutIfNeeded()
97+ if !firstStack {
97− largeStack.addArrangedSubview(.spacer(verticalPadding))
98+ largeStack.addArrangedSubview(.spacer(verticalPadding))
99+ }
98 largeStack.addArrangedSubview(.view(lastStack))
100 largeStack.addArrangedSubview(.view(lastStack))
99 largeStack.frame.origin = CGPoint.zero
101 largeStack.frame.origin = CGPoint.zero
100 largeStack.layoutIfNeeded()
102 largeStack.layoutIfNeeded()
Melk/SecondaryViewController.swift+22−3
@@ -27,19 +27,38 @@ class SecondaryViewController: UIViewController {
27}
27}
28
28
29class SecondaryView: UIView {
29class SecondaryView: UIView {
30+
31+
32+ private let spacer: CGFloat = 16
33+
30 func add(result: StreamingServiceResult) {
34 func add(result: StreamingServiceResult) {
31 switch result {
35 switch result {
32 case .post(let post):
36 case .post(let post):
37+ let card = CardView()
33 card.post = post
38 card.post = post
39+ cards.addArrangedSubview(.spacer(spacer))
40+ cards.addArrangedSubview(.view(card))
34 }
41 }
35 }
42 }
36
43
37− let card = CardView()
44+// private let card = CardView()
45+ private let cards = StackView(axis: .horizontal, alignment: .top)
38
46
39 override init(frame: CGRect) {
47 override init(frame: CGRect) {
40 super.init(frame: frame)
48 super.init(frame: frame)
41− card.frame.origin = CGPoint(x: 20, y: 20)
49+ addSubview(cards)
42− addSubview(card)
50+ }
51+
52+
53+ private let padding = CGPoint(x: 32, y: 32)
54+
55+ override func layoutSubviews() {
56+ super.layoutSubviews()
57+ UIView.animate(withDuration: 0.4, delay: 0.0, options: [.curveEaseOut], animations: {
58+ self.cards.layoutIfNeeded()
59+ self.cards.frame.origin.y = self.padding.y
60+ self.cards.frame.origin.x = self.frame.width - self.padding.x - self.cards.frame.width
61+ }, completion: nil)
43 }
62 }
44
63
45 required init?(coder aDecoder: NSCoder) {
64 required init?(coder aDecoder: NSCoder) {