on master help sign in
Basic animations are now working.
commit0cde9886f0f8ca2d3d6681abd4a3408808a12861 authorilyakooo0 <ilyakooo0@gmail.com> dateSat 22 Jul 2017, 01:12 (9 years ago) parentfda9158
3 files changed+34−8
Melk/CardView.swift+9−4 Melk/CollectionView.swift+3−1 Melk/SecondaryViewController.swift+22−3
Melk/CardView.swift+9−4
@@ -16,7 +16,7 @@ class CardView: UIView {
1616 update()
1717 }
1818 }
19− var width: CGFloat = 300 {
19+ var minWidth: CGFloat = 300 {
2020 didSet {
2121 update()
2222 }
@@ -84,11 +84,15 @@ class CardView: UIView {
8484 largeStack.addArrangedSubview(.spacer(vPadding1))
8585
8686
87+ let width = max(minWidth - 2 * padding.x, userView.frame.width)
88+
89+
8790 let photoView = CollectionView()
8891 photoView.alignment = .top
8992 photoView.horizontalPadding = 8
9093 photoView.verticalPadding = 8
9194 photoView.padding = CGPoint.zero
95+ photoView.maxWidth = width
9296 var maxPhotoDim: CGFloat = 150
9397 if let attachments = post?.attachments {
9498 for attachment in attachments {
@@ -98,6 +102,7 @@ class CardView: UIView {
98102 if var pWidth = photo.width.value >>> {CGFloat($0)},
99103 var pHeight = photo.height.value >>> {CGFloat($0)} {
100104 let photoV = UIImageView()
105+ photoV.layer.minificationFilter = kCAFilterTrilinear
101106 photo.image?.load(into: photoV)
102107 var k: CGFloat!
103108 if pWidth > pHeight {
@@ -123,7 +128,7 @@ class CardView: UIView {
123128 textHeight -= padding.y + vPadding1 + userView.frame.height
124129 if let count = post?.attachments.count{
125130 if count > 0 {
126− textHeight -= vPadding2 + photoView.frame.height
131+ textHeight -= vPadding2 + photoView.frame.height + padding.y
127132 }
128133 }
129134 print(textHeight)
@@ -132,7 +137,7 @@ class CardView: UIView {
132137
133138 let body = UILabel()
134139 body.numberOfLines = 0
135− let bodyWidth: Double = Double(width - padding.x * 2)
140+ let bodyWidth: Double = Double(width)
136141 body.font = UIFont.systemFont(ofSize: 22, weight: UIFontWeightSemibold)
137142 body.text = post?.body
138143 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 {
148153 }
149154 }
150155
151− frame.size = CGSize(width: width, height: height)
156+ frame.size = CGSize(width: width + padding.x * 2, height: height)
152157
153158 }
154159}
Melk/CollectionView.swift+3−1
@@ -94,7 +94,9 @@ class CollectionView: UIView {
9494 }
9595 }
9696 lastStack.layoutIfNeeded()
97− largeStack.addArrangedSubview(.spacer(verticalPadding))
97+ if !firstStack {
98+ largeStack.addArrangedSubview(.spacer(verticalPadding))
99+ }
98100 largeStack.addArrangedSubview(.view(lastStack))
99101 largeStack.frame.origin = CGPoint.zero
100102 largeStack.layoutIfNeeded()
Melk/SecondaryViewController.swift+22−3
@@ -27,19 +27,38 @@ class SecondaryViewController: UIViewController {
2727}
2828
2929class SecondaryView: UIView {
30+
31+
32+ private let spacer: CGFloat = 16
33+
3034 func add(result: StreamingServiceResult) {
3135 switch result {
3236 case .post(let post):
37+ let card = CardView()
3338 card.post = post
39+ cards.addArrangedSubview(.spacer(spacer))
40+ cards.addArrangedSubview(.view(card))
3441 }
3542 }
3643
37− let card = CardView()
44+// private let card = CardView()
45+ private let cards = StackView(axis: .horizontal, alignment: .top)
3846
3947 override init(frame: CGRect) {
4048 super.init(frame: frame)
41− card.frame.origin = CGPoint(x: 20, y: 20)
42− addSubview(card)
49+ addSubview(cards)
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)
4362 }
4463
4564 required init?(coder aDecoder: NSCoder) {