简体   繁体   English

swift animateWithDuration在iOS 7中不起作用

[英]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. 我的动画在iOS 8.1中运行良好,但在iOS 7.1中,该按钮仅出现在应该没有动画的位置。

The button has leading, trailing and bottom constraints of 0, and height constraint of 80. The constraints are setup in the storyboard. 该按钮的开头,结尾和底部约束为0,高度约束为80。这些约束在情节提要中进行设置。

In the viewWillAppear method I change the bottom constraint to -80 so it isn't seen in the beginning. 在viewWillAppear方法中,我将底部约束更改为-80,因此一开始就看不到它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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