ios - animateWithDuration - UITextField 中的淡入/淡出动画

标签 ios swift animatewithduration

我正在开发的应用程序中有一个计分器。我希望过渡能够淡入新乐谱,而旧乐谱会放大并淡出,而不是仅仅改变数字。

以下是我得到的最接近的:

     UIView.animateWithDuration(0.6, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {

        self.scoreOutlet.text = "\(self.numberFormatter.stringFromNumber(self.score)!)"
        self.scoreOutlet.transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.scoreOutlet.alpha = 0.0

        }) { (_) in
            UIView.animateWithDuration(0.0, animations: {

                self.scoreOutlet.transform = CGAffineTransformMakeScale(1.0, 1.0)
                self.scoreOutlet.alpha = 1.0

            })
    }

我希望这些同时发生。我意识到关闭发生在初始动画的 0.6 秒之后,但我认为嵌套 animateWithDuration block 不是这里最干净的方法。

期望的结果

如果分数从 20 变为 25: 25 会淡入,但与此同时,20 会淡出,放大并略微向上移动(略微向上移动的部分不在我上面的代码尝试中。)

最佳答案

制作 2 个标签,1 个用于旧分数,1 个用于新分数,这样两者都可以在 1 个动画中完成,并在完成时,将新分数设置为 oldScoreLabel,这样另一个就可以准备好了更新分数。

你应该得到这样的东西:

 UIView.animateWithDuration(0.6, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
        self.scoreOutlet.alpha = 0.0

        self.newScoreOutlet.text = "\(self.numberFormatter.stringFromNumber(self.score)!)"
        self.newScoreOutlet.transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.newScoreOutlet.alpha = 1.0

        }) { (_) in
            UIView.animateWithDuration(0.0, animations: {

                self.newScoreOutlet.transform = CGAffineTransformMakeScale(1.0, 1.0)
                self.newScoreOutlet.alpha = 0.0

                self.scoreOutlet.alpha = 1.0
                self.scoreOutlet.text = self.newScoreOutlet.text
            })
    }

关于ios - animateWithDuration - UITextField 中的淡入/淡出动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37338547/

相关文章:

ios - 如何在 traitCollectionDidChange 的 View Controller 中更改 UIImageView 图像

ios - 在 Swift 中导入 Swift 框架 : "Use of undeclared type ' MyCustomView'"

ios - 防止快速点击 View

ios - 如何在 swift 中定义 HEX 颜色宏

swift - 如何在 Swift 中使用 Xcode Logger

ios - 定时器上的 Objective C 加载图标

ios - 连续动画调用不起作用

ios - Phonegap:下载当前设置的证书和配置

iOS 12 推送通知在以下版本中不起作用,在 iOS 12 中未收到推送通知

ios - UITabBarController 不显示 "More"按钮