Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I remove the view from super view after a disappear animation? #7

Closed
Sweeper777 opened this issue Sep 10, 2017 · 5 comments
Closed

Comments

@Sweeper777
Copy link

transform(duration: 0.5, transforms: [
        .scale(x: 0, y: 0)
        ]).do { [weak self] in
            self?.removeFromSuperview()
    }

I have the above animation. I was hoping that when performed, the view will shrink and after 0.5 seconds it will be removed from the super view. However, it actually just make the view disappear without the animation. I thought the do block will run code after the animations. Am i misunderstanding this? How can I remove the view from super view after animation finishes?

@rchatham
Copy link
Owner

rchatham commented Sep 10, 2017

You can call removeFormSuperview in the completion block when you call perform. Will that work for your use case?

@Sweeper777
Copy link
Author

I think that should work. However, I want to write the removeFromSuperview call in the view class, so the VC, who is performing the animation, doesn't need to worry about that. Is there any way to do this?

@rchatham
Copy link
Owner

I believe your assumption above in your original comment should work. Is this not happening correctly? You may need to call layoutIfNeeded() again to get the vc to show that the view has been removed.

@Sweeper777
Copy link
Author

Actually I just found out that doing a scale animation of (0,0) will just make the view disappear immediately. This made it seem like the view is removed before the animation finishes. I changed both x and y to 0.1 and it works.

@rchatham
Copy link
Owner

Awesome! This is good info. Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants