SWIFT animateWithDuration iOS中7不工作 [英] swift animateWithDuration not working in iOS 7

查看:198
本文介绍了SWIFT animateWithDuration iOS中7不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的iOS 8.1,但7.1的iOS按钮只是出现在那里应该是没有动画。运行良好的动画,多数民众赞成

按钮有领导,拖尾和0底部的限制,以及80高度约束的约束是在故事板的设置。

在viewWillAppear中方法变更底部约束至-80所以它不是在开始可见。

当用户presses一个按钮,按钮为动画了,我跑这个方法:

  FUNC animateCtaUp(){
    self.ctaView.layoutIfNeeded()
    UIView.animateWithDuration(0.5,延迟:0,选项:.CurveEaseOut,动画:{
            self.ctaViewBottomConstraint.constant = 0
            self.ctaView.layoutIfNeeded()
        }完成:{完成了    })
}


解决方案

基本上有2错误。

第一个问题是:我有没有布局约束的视图。当我加入他们的动画之一,开始运行。

第二个错误是:我打电话

  self.ctaView.layoutIfNeeded()

相反,我应该叫

  self.view.layoutIfNeeded

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

这篇关于SWIFT animateWithDuration iOS中7不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆