on master help sign in
Seem to have finalized animations
commit8f0e1836c466d5a13061d7ce5bb8b81568d2c0a1 authorilyakooo0 <ilyakooo0@gmail.com> dateSat 22 Jul 2017, 18:47 (9 years ago) parent0cde988
6 files changed+119−7
Melk.xcodeproj/project.pbxproj+13−1 Melk/CardContainer.swift+79 Melk/CardView.swift+3−1 Melk/MainCoordinator.swift+1−1 Melk/SecondaryViewController.swift+22−3 Melk/StackView.swift+1−1
Melk.xcodeproj/project.pbxproj+13−1
@@ -10,6 +10,7 @@
1010 0919AEA71F0D3D9D00894FFA /* SecondaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0919AEA61F0D3D9D00894FFA /* SecondaryViewController.swift */; };
1111 0919AEA91F0D459600894FFA /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0919AEA81F0D459600894FFA /* CardView.swift */; };
1212 0919AEAD1F0D706700894FFA /* StackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0919AEAC1F0D706700894FFA /* StackView.swift */; };
13+ 09231E351F2394ED007C836D /* CardContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09231E341F2394ED007C836D /* CardContainer.swift */; };
1314 09939A561F097DA90014719D /* TableViewCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09939A551F097DA90014719D /* TableViewCells.swift */; };
1415 09A456361F0ED9A800BAC32D /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A456351F0ED9A800BAC32D /* CollectionView.swift */; };
1516 09AFAB041F159C9200EBD200 /* StreamingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AFAB031F159C9200EBD200 /* StreamingService.swift */; };
@@ -69,6 +70,7 @@
6970 0919AEA61F0D3D9D00894FFA /* SecondaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecondaryViewController.swift; sourceTree = "<group>"; };
7071 0919AEA81F0D459600894FFA /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
7172 0919AEAC1F0D706700894FFA /* StackView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StackView.swift; sourceTree = "<group>"; };
73+ 09231E341F2394ED007C836D /* CardContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardContainer.swift; sourceTree = "<group>"; };
7274 09939A551F097DA90014719D /* TableViewCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCells.swift; sourceTree = "<group>"; };
7375 09A456351F0ED9A800BAC32D /* CollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = "<group>"; };
7476 09AFAAFF1F159AE300EBD200 /* SwiftyJSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyJSON.framework; path = Carthage/Build/iOS/SwiftyJSON.framework; sourceTree = SOURCE_ROOT; };
@@ -117,6 +119,15 @@
117119/* End PBXFrameworksBuildPhase section */
118120
119121/* Begin PBXGroup section */
122+ 09231E331F2394C5007C836D /* Card */ = {
123+ isa = PBXGroup;
124+ children = (
125+ 0919AEA81F0D459600894FFA /* CardView.swift */,
126+ 09231E341F2394ED007C836D /* CardContainer.swift */,
127+ );
128+ name = Card;
129+ sourceTree = "<group>";
130+ };
120131 098397F71F1E887F008C88DD /* Main */ = {
121132 isa = PBXGroup;
122133 children = (
@@ -176,11 +187,11 @@
176187 098397F71F1E887F008C88DD /* Main */,
177188 098397F81F1E888F008C88DD /* Secondary */,
178189 098397F91F1E88A3008C88DD /* Streaming */,
190+ 09231E331F2394C5007C836D /* Card */,
179191 09BF41EE1F07F71F00AFAD57 /* AppDelegate.swift */,
180192 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
181193 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
182194 09F03F351F1674ED000CE916 /* VKServer.swift */,
183− 0919AEA81F0D459600894FFA /* CardView.swift */,
184195 09939A551F097DA90014719D /* TableViewCells.swift */,
185196 09BF420D1F0833A700AFAD57 /* LocalVKDataTypes.swift */,
186197 09BF42151F0834D400AFAD57 /* VKPublicCrap.swift */,
@@ -294,6 +305,7 @@
294305 09BF42181F08352E00AFAD57 /* VKData.swift in Sources */,
295306 09BF42101F0833C100AFAD57 /* MainCoordinator.swift in Sources */,
296307 09A456361F0ED9A800BAC32D /* CollectionView.swift in Sources */,
308+ 09231E351F2394ED007C836D /* CardContainer.swift in Sources */,
297309 09BF42131F08341B00AFAD57 /* MyWeirdness.swift in Sources */,
298310 0919AEA91F0D459600894FFA /* CardView.swift in Sources */,
299311 09BF42321F08388100AFAD57 /* SecondaryCoordinator.swift in Sources */,
Melk/CardContainer.swiftnew file+79
@@ -0,0 +1,79 @@
1+//
2+// CardContainer.swift
3+// Melk
4+//
5+// Created by Ilya Kos on 7/22/17.
6+// Copyright © 2017 Ilya Kos. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class CardContainer: UIView {
12+
13+ func animate() {
14+ blurView.effect = blur
15+ card.transform = smallTransform
16+ card.layer.opacity = 0
17+ UIView.animate(withDuration: 0.5, delay: 0, options: [.curveEaseInOut], animations: {
18+ self.card.transform = self.normalTransform
19+ self.blurView.effect = nil
20+ self.card.layer.opacity = 1
21+ }, completion: nil)
22+ }
23+
24+ // MARK: Passthrough to CardView
25+ var post: WallPost? {
26+ get {
27+ return card.post
28+ }
29+ set {
30+ card.post = newValue
31+ }
32+ }
33+
34+ var minWidth: CGFloat {
35+ get {
36+ return card.minWidth
37+ }
38+ set {
39+ card.minWidth = newValue
40+ }
41+ }
42+
43+
44+ var height: CGFloat {
45+ get {
46+ return card.height
47+ }
48+ set {
49+ card.height = newValue
50+ }
51+ }
52+
53+ private let card: CardView
54+ private let blurView = UIVisualEffectView()
55+ private let blur = UIBlurEffect(style: UIBlurEffectStyle.light)
56+ private let scale: CGFloat = 0.35
57+ private let smallTransform: CGAffineTransform
58+ private let normalTransform = CGAffineTransform(scaleX: 1, y: 1)
59+
60+ override init(frame: CGRect) {
61+ card = CardView(frame: frame)
62+ smallTransform = CGAffineTransform(scaleX: scale, y: scale)
63+ super.init(frame: frame)
64+ addSubview(card)
65+ addSubview(blurView)
66+ }
67+
68+ required init?(coder aDecoder: NSCoder) {
69+ fatalError("init(coder:) has not been implemented")
70+ }
71+
72+ override func layoutSubviews() {
73+ super.layoutSubviews()
74+ card.layoutIfNeeded()
75+ self.frame = card.frame
76+ blurView.frame = card.frame
77+ }
78+
79+}
Melk/CardView.swift+3−1
@@ -153,7 +153,9 @@ class CardView: UIView {
153153 }
154154 }
155155
156− frame.size = CGSize(width: width + padding.x * 2, height: height)
156+ largeStack.layoutIfNeeded()
157+
158+ frame.size = CGSize(width: width + padding.x * 2, height: min(height, largeStack.frame.height))
157159
158160 }
159161}
Melk/MainCoordinator.swift+1−1
@@ -44,7 +44,7 @@ class MainCoordinator {
4444// }
4545 print("didAuthorize")
4646 window.rootViewController = navC
47− stream.rules = ["я", "а"]
47+ stream.rules = ["я", "а", "и"]
4848 stream.connect()
4949 }
5050
Melk/SecondaryViewController.swift+22−3
@@ -34,11 +34,14 @@ class SecondaryView: UIView {
3434 func add(result: StreamingServiceResult) {
3535 switch result {
3636 case .post(let post):
37− let card = CardView()
37+ let card = CardContainer()
3838 card.post = post
3939 cards.addArrangedSubview(.spacer(spacer))
4040 cards.addArrangedSubview(.view(card))
41+ card.animate()
4142 }
43+ self.layoutIfNeeded(animated: true)
44+// self.setNeedsLayout(animated: true) // Doesn't work for some reason
4245 }
4346
4447// private let card = CardView()
@@ -49,16 +52,32 @@ class SecondaryView: UIView {
4952 addSubview(cards)
5053 }
5154
55+ func setNeedsLayout(animated: Bool) {
56+ self.animate = animated
57+ self.setNeedsLayout()
58+ }
59+ func layoutIfNeeded(animated: Bool) {
60+ self.animate = animated
61+ self.layoutIfNeeded()
62+ }
63+ private var animate: Bool = false
5264
5365 private let padding = CGPoint(x: 32, y: 32)
5466
5567 override func layoutSubviews() {
5668 super.layoutSubviews()
57− UIView.animate(withDuration: 0.4, delay: 0.0, options: [.curveEaseOut], animations: {
69+ let updates = {
5870 self.cards.layoutIfNeeded()
5971 self.cards.frame.origin.y = self.padding.y
6072 self.cards.frame.origin.x = self.frame.width - self.padding.x - self.cards.frame.width
61− }, completion: nil)
73+ }
74+ if animate {
75+ UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.6, options: [], animations: updates, completion: nil)
76+// UIView.animate(withDuration: 0.4, delay: 0.0, options: [.curveEaseOut], animations: updates, completion: nil)
77+ } else {
78+ updates()
79+ }
80+ animate = false
6281 }
6382
6483 required init?(coder aDecoder: NSCoder) {
Melk/StackView.swift+1−1
@@ -62,7 +62,7 @@ class StackView: UIView {
6262 height += a
6363 }
6464 case .view(let view):
65−
65+ view.layoutIfNeeded()
6666 switch axis {
6767 case .horizontal:
6868 view.frame.origin.x = width