简体   繁体   中英

Swift do I need layoutifneeded()

I am animating a view by:

@IBAction func showInfo(sender: AnyObject) {

    UIView.animateWithDuration(1,
        delay: 0,
        usingSpringWithDamping: 0.7,
        initialSpringVelocity: 0.5,
        options: nil,
        animations: {
            self.infoContainer.frame.origin.y = CGFloat(30)
        }, completion: nil
    )

}

My question now is if I need to run layoutIfNeeded() afterwards?

You need to call layoutIfNeeded() when you change constraints. You don't need to call it when animating by origin

Since you are animating by setting a new frame, you don't need to call layoutIfNeeded() .

My guess is that you asked this question because it's not working for you. If you setup the view with AutoLayout, and try to modify the frame directly, it won't work, you have to animate by modifying the constants in the constraints.

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