简体   繁体   中英

Animations: moving a UIView up and off the screen by its height - SWIFT

I am trying to move a UIView up and off the screen by its height in ios. Below is my code for doing this. What I am finding is that the UIView does indeed move up and off the screen but instead of moving slowly as intended it continues to move off instantaneously without animation. Please can someone advise?

 UIView.animate(withDuration: 300, animations: {
                    let heightOfViewContainingProgrBar = self.viewContainingProgressBar.frame.height
                    self.viewContainingProgressBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: -heightOfViewContainingProgrBar).isActive = true
                })

您需要在动画块内调用layoutIfNeeded(用于视图或其中的一个超级视图)。

Add

self.view.layoutIfNeeded()

inside animation block

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM