swift animateWithDuration not working in iOS 7

落花浮王杯 提交于 2019-12-12 03:17:00

问题


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:


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


来源:https://stackoverflow.com/questions/27907570/swift-animatewithduration-not-working-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!