Swift UIView animateWithDuration完成关闭立即调用 [英] Swift UIView animateWithDuration completion closure called immediately

查看:101
本文介绍了Swift UIView animateWithDuration完成关闭立即调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在指定的持续时间后调用此UIView动画的完成关闭,但是它似乎会立即触发...

I'm expecting the completion closure on this UIView animation to be called after the specified duration, however it appears to be firing immediately...

 UIView.animateWithDuration(
        Double(0.2),
        animations: {
            self.frame = CGRectMake(0, -self.bounds.height, self.bounds.width, self.bounds.height)
        },
        completion: { finished in
            if(finished) {
                self.removeFromSuperview()
            }
        }
    )

还有其他人遇到过吗?我已经读到其他人在使用中心而不是框架移动视图方面取得了更大的成功,但是我在这种方法上也遇到了同样的问题。

Has anyone else experienced this? I've read that others had more success using the center rather than the frame to move the view, however I had the same problems with this method too.

推荐答案

最后,我将动画从 hitTest()移到了 touchesBegan() UIView

I resolved this in the end by moving the animation from hitTest() and into touchesBegan() in the UIView

这篇关于Swift UIView animateWithDuration完成关闭立即调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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