swift animateWithDuration not working in iOS 7

2019-09-16 11:43发布

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

    })
}

1条回答
神经病院院长
2楼-- · 2019-09-16 12:11

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
查看更多
登录 后发表回答