简体   繁体   中英

swift animateWithDuration not working in iOS 7

I have an animation thats running fine in iOS 8.1 but in iOS 7.1 the button just appears where it is supposed to be without animation.

The button has leading, trailing and bottom constraints of 0, and height constraint of 80. The constraints are setup in the storyboard.

In the viewWillAppear method I change the bottom constraint to -80 so it isn't seen in the beginning.

When the user presses a button, the button should animate up, I run this method:

func animateCtaUp() {
    self.ctaView.layoutIfNeeded()
    UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
            self.ctaViewBottomConstraint.constant = 0
            self.ctaView.layoutIfNeeded()
        }, completion: { finished in

    })
}

Basically there were 2 bugs.

The first one was: I had a view without layout constraints. When I added them one of the animations started running.

The second bug was: I was calling

self.ctaView.layoutIfNeeded()

Instead I should be calling

self.view.layoutIfNeeded

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