Auto Layout Constraint Animations
AppStore JSON APIs
In this lesson, I'll go ahead and introduce the proper fixes for dealing with animations in iOS. To eliminate the glitchy behavior we're currently seeing, I'll teach you the ways of implementing auto layout constraints and how to animate them. This process is somewhat tedious but once you get familiar with it, you should be able to easily use it again in the future.

Comments (16)
Tube
4 years ago
This is my favorite course so far! I hope you plan to show us the best ways to put shadows on the Today cards. Plus, when the card is clicked, it should shrink a little and then spring open when the click ends.
Brian Voong
4 years ago
bingwei
4 years ago
When I clicked the card, I found an error message in the console as following: AppStoreJSONApis[5492:181955] Warning once only: Detected a case where constraints ambiguously suggest a size of zero for a collection view cell's content view. We're considering the collapse unintentional and using standard size instead. Do you have any idea about this? Thanks Brian! I learned a lot from this course!
Brian Voong
4 years ago
tsangaris
4 years ago
I had the same warning. Turns out that this is a feature of iOS 8 and onwards (not the "you are holding it wrong" type of feature). You can read more here: https://stackoverflow.com/questions/25902288/detected-a-case-where-constraints-ambiguously-suggest-a-height-of-zero#answer-26359823
waynezong
4 years ago
Try to specify the size for the header or footer of the table view if there are any.
Tube
4 years ago
When you select the card and open the detail vc, then scroll up and click to dismiss, the close button lingers when you return to the card. Also, your rig must be much faster than mine. After returning from the detail vc, the card is unclickable for a noticeable amount of time. The delay has to do with dismissing the detail vc after you return, I guess!
Brian Voong
4 years ago
Tube
4 years ago
Smaller lag. Fast clickers would still have the problem. Before you got things working so well, you could see the lag. Without the tap, we need a swipe down dismiss.
Brian Voong
4 years ago
Tube
4 years ago
I was amazed that you finally used a child VC. Good on ya! But, I had read that 3 calls are necessary for allocation and deallocation: https://www.swiftbysundell.com/posts/using-child-view-controllers-as-plugins-in-swift) extension UIViewController { func add(_ child: UIViewController) { addChild(child) view.addSubview(child.view) child.didMove(toParent: self) } func remove() { // Just to be safe, we check that this view controller // is actually added to aparent before removing it. guard parent != nil else { return } willMove(toParent: nil) view.removeFromSuperview() removeFromParent() } }
Brian Voong
4 years ago
Tube
4 years ago
Here's another good one: Building complex screens with Child ViewControllers https://mecid.github.io/2019/02/27/building-complex-screens-with-child-viewcontrollers/
TWei
4 years ago
Hi Brian, what do you think the difficulty level of this animation? 0 - 10
Brian Voong
4 years ago
TWei
4 years ago
just 5... I feel animation requires more knowledge and experience. Look forward for more courses this year. :)
Brian Voong
4 years ago
TWei
4 years ago
Yeah I saw that one. I’m thinking is there something you can’t build.
TWei
4 years ago
You tai niu bi le :)
Brian Voong
4 years ago
TWei
4 years ago
Thanks for your effort. 90% of my iOS skill comes from your course. Need more :)
Brian Voong
4 years ago
TWei
4 years ago
Great. I was about to say through all your course I feel pretty comfortable with UICollectionViews, UITableViews and Auto Layout. Definitely want to learn more beyond that. :)
tonytech
4 years ago
i feel like a chimp at the moment, but im going to keep on pushing through
Brian Voong
4 years ago
alexbuga
4 years ago
Dude, I bought this course just to watch how you did the Today animations. I've managed to implement the Transitioning delegate by myself, and although it's cool that you can swipe back to dismiss interactively, IT'S NOT WORTH THE EFFORT! Your approach is way way more simpler and it freaking works. Thanks. This alone was worth 60$
calube
4 years ago
same here, I bought this course to see his transition implementation. Sadly it might not be this easy for me, because my detail view controller needs a nav bar. I think when he adds the child view controller I could see if I can do the same animation but with UINavigationController with a root view controller.
Brian Voong
4 years ago
calube
4 years ago
Amazing, thanks Brian!
hwatanabe9393
4 years ago
I think I understood most out of it except the super.tableView(tableView, heightForRowAt: indexPath) part. Based on my understanding, tableview by default has really small size; therefore, we have to override this function to match with the height which we want. So I guess what I want to say is that how come by calling super.tableView(tableView, heightForRowAt: indexPath), tableview manage to autofit the height of the cell... Any hint or explanation will be very appreciated.
hwatanabe9393
4 years ago
Sorry I wrote wrong: "tableview by default has really small size" => "tableview by default has really small cell size"
Tokyojogo
4 years ago
Hi Brian, thank you, this is such a great course! I have a question, when using transitioningdelegate, i know it uses a container and its important to remove the previous screen from the container after presenting the new screen. With this way of animating, do we need to do something like that? What will happen if the FullScreenController presents another view modally and I want to unwind to the very first screen? Thank you.
Sebastien Menozzi
4 years ago
Hi Brian, I followed your tutorial but one more thing I had to do is to deactivate all the constraints after the dismiss animation completion. Otherwise, I had a "Can't satisfied multiple constraints" warning and the dismiss animation was buggy after the modal was opened once (only the first dismiss was working well). It's a mystery for me because I had the exact same code and I didn't forget the 2 view.layoutIfNeeded(). Anyway, it works well now though :)
Sebastien Menozzi
4 years ago
Actually I know why! I was using a global variable controller and I was directly retrieving the view by using controller.view.. It's clear now why it happened...
Eduard Hilgenberg
3 years ago
The part with self.appFullscreenController.tableView.contentOffset = .zero doesn't work in iOS 13 anymore.
李承諴
3 years ago
I check the contentOffset in tableview It should be CGPoint(0,0), but It is CGPoint(0,-44) So I reset the contentOffset base on the top padding of safe area It's work for me
learnberry
3 years ago
Where in the code can I fix this?
bermillo.mrk
3 years ago
Hi Eduard Hilgenberg, I have fixed this by putting the contentOffset code below the layoutIfneed(): .... self.view.layoutIfNeeded() self.appFullScreenController.tableView.contentOffset = .zero ...
angseton
3 years ago
Hi Brian! The transition of these two screens was one of the main reasons I purchased this course (which I'm enjoying a lot so far). Unfortunately it remains really glitchy in iOS 13. Were you able to find a solution to this problem?
Brian Voong
3 years ago
slcott
3 years ago
I just tested it and it looks good when presenting but there is still a glitch when the controller dismisses. I am using XCode 11.3 and my simulator is running iOS 13.3.
Brian Voong
3 years ago
matlyles
3 years ago
so was having some issues with closing , if your on xcode 11 and iOS 13, this fixed it or me: in the close animation , put the scrollToRow code after. don't use the contentOffSet. simulator may still show an issue, but test on your phone, should be perfect self.view.layoutIfNeeded() //self.appFullScreenController.tableView.tableView.contentOffset = .zero self.appFullScreenController.tableView.tableView.scrollToRow(at: [0,0], at: .top, animated: true)
Brian Voong
3 years ago
CogiLiu
3 years ago
Dear Brian, One symptom, when TodayCell scroll to top < saftAreaInset.top or the bottom > view.frame.height The closing animation will include the AppFullscreenController top safe area (notch background) There is no problem will TodayCell location at center of list view Seems the animation will not shrink safeArea background color more high priority I use SwiftUI to create initial project. It different with "Download Project" Are there any suggestion for the issue? Thanks a lot
Brian Voong
3 years ago
CogiLiu
3 years ago
Thanks your very quick reply
seventhaxis
3 years ago
Having an issue where cells that encroach into the top and bottom safeAreaLayoutGuides do not animate back correctly. It appears as though the top safe area inset for the expanded view is being preserved. Any chance you could take a look? https://github.com/seventhaxis/lbta-appstore
Brian Voong
3 years ago
seventhaxis
3 years ago
Yours seems to work fine, but I deviated and used a scroll view instead of a table view. Let me know if you get a chance to take a look at my project. I'd greatly appreciate it.
Brian Voong
3 years ago
seventhaxis
3 years ago
Brian, I tried taking a look at the project downloaded from lesson 59, but it is extremely different from the design to this point that it's incredibly difficult to connect the dots.
nfchacker
2 years ago
the code self.appFullscreenController.tableView.contentOffset = .zero in handleRemoveRedView function no longer working with iOS 14, Could you please find another solution?
nfchacker
2 years ago
I Just read comments below and found call scrollToRow after layoutIfNeeded() works fine.
HELP & SUPPORT