willowtreeapps/spruce-ios

Can't get view to animate

16alexanders opened this issue · 9 comments

Hi I'm trying to animate an existing UILabel...

I have this in my viewDidLoad method:

HomeView.spruce.prepare(with: [.slide(.right, .severely)])
HomeView.spruce.animate([.slide(.right, .severely)])

But nothing happens when the view loads. I honestly don't understand what I could be doing wrong the API seems very simple. I tried explicitly casting the Label to a UIView even though it inherits from it...
let v = HomeView as UIView

evliu commented

if it's in your viewDidLoad, it probably animates before your view appears. Try moving .animate( to viewDidAppear

I overrode viewDidAppear and threw animate in there and it still didn't work. Also linked the animate function to an IBAction button press to control when it happens and it doesn't happen at all. I was thinking... Is this because of constraints in my code or something.

evliu commented

I see, i made an IBOutlet UIImageView and UILabel as well to test and it doesn't animate for me either. Not sure why at this point.

@16alexanders Spruce should still work if you have constraints or not. Seems like something fishy is going on here haha. Any chance you can post your code (project) or a little more explanation of your view setup?

My intention is that if a user presses "Choose Home" then the 'apartment' option and logo will slide/spring offscreen to the right, and the 'home' option and logo will slide to the center.
(vice versa for other button choice)

@16alexanders So from what I can tell, it looks like you may be using Spruce in a different way then intended. Spruce is designed to animate the subviews of a view. That means when you call yourView.spruce.animate this will affect all of the subviews of that view. Since you are calling Home.spruce.animate you are trying to animate the subviews of a UILabel which doesn't have any subviews. For the animation that you are going for, I would say to use a basic UIView.animate block.

To use Spruce, I would say this page would look great with an entrance animation. You can call view.spruce.animate when the view appears, and then all of the buttons on the screen will animate in at a delay offset.

Hopefully this answers your question.

I see, so I guess Spruce is used to animate the various subviews of a UIView with a certain effect / sorting function rather than animate individual views. Thanks for clarifying.