Swift Animate duration not working in CGAffineTran

2019-08-27 03:31发布

When I am translating one view with an animation of 1 second it is not working, but when I am executing the transform.identity it works fine.

Here is my code:

func hideCarousel() {
    UIView.animate(withDuration: 1, animations: {
        self.carouselER.transform  = CGAffineTransform(translationX: 0, y: 200)
    })
}

func showCarousel() {
    UIView.animate(withDuration: 1, animations: {
        self.carouselER.transform = .identity
    })
}

Carousel Not Working

1条回答
该账号已被封号
2楼-- · 2019-08-27 04:08

To solve this issue I forced the animation to run in the main thread. Every time that you have problems with the performance of your UI elements like your animations or updating your label texts, try forcing to run the UI change in the main thread.

    DispatchQueue.main.async {
        UIView.animate(withDuration: 1, animations: {
            self.carouselER.transform  = CGAffineTransform(translationX: 0, y: 200)
        })
    }

I have also faced that problem with one timer that updated a label, but in this issue I thought it was some kind of problem of the CGAffineTransform.

Carousel Working

查看更多
登录 后发表回答