我希望像在iOS Powerpoint中一样在iOS Swift中为文本添加动画效果。这是我在Swift中尝试做的事情的链接:
http://www.ellenfinkelstein.com/pptblog/text-animation-techniques/
(我正在看的是他们在网站上的例3中的打字机效果)
我似乎找不到如何做到这一点的方法。
感谢任何帮助:)
编辑: 目前我正在使用一种天真的方法并逐一淡化它们。但它是对我的信号
ViewController.swift:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var hash1: UILabel!
@IBOutlet weak var i: UILabel!
@IBOutlet weak var n: UILabel!
@IBOutlet weak var c: UILabel!
@IBOutlet weak var l: UILabel!
@IBOutlet weak var u: UILabel!
@IBOutlet weak var d: UILabel!
@IBOutlet weak var e: UILabel!
@IBOutlet weak var leftarrow: UILabel!
@IBOutlet weak var s: UILabel!
@IBOutlet weak var t: UILabel!
@IBOutlet weak var d1: UILabel!
@IBOutlet weak var i1: UILabel!
@IBOutlet weak var o: UILabel!
@IBOutlet weak var dot: UILabel!
@IBOutlet weak var h: UILabel!
@IBOutlet weak var rightarrow: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.hash1.alpha = 0
self.i.alpha = 0
self.n.alpha = 0
self.c.alpha = 0
self.l.alpha = 0
self.u.alpha = 0
self.d.alpha = 0
self.e.alpha = 0
self.leftarrow.alpha = 0
self.s.alpha = 0
self.t.alpha = 0
self.d1.alpha = 0
self.i1.alpha = 0
self.o.alpha = 0
self.dot.alpha = 0
self.h.alpha = 0
self.rightarrow.alpha = 0
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(0.1, animations: { () -> Void in self.hash1.alpha = 1.0})
UIView.animateWithDuration(0.2, animations: { () -> Void in self.i.alpha = 1.0})
UIView.animateWithDuration(0.3, animations: { () -> Void in self.n.alpha = 1.0})
UIView.animateWithDuration(0.4, animations: { () -> Void in self.c.alpha = 1.0})
UIView.animateWithDuration(0.5, animations: { () -> Void in self.l.alpha = 1.0})
UIView.animateWithDuration(0.6, animations: { () -> Void in self.u.alpha = 1.0})
UIView.animateWithDuration(0.7, animations: { () -> Void in self.d.alpha = 1.0})
UIView.animateWithDuration(0.8, animations: { () -> Void in self.e.alpha = 1.0})
UIView.animateWithDuration(0.9, animations: { () -> Void in self.leftarrow.alpha = 1.0})
UIView.animateWithDuration(1.0, animations: { () -> Void in self.s.alpha = 1.0})
UIView.animateWithDuration(1.1, animations: { () -> Void in self.t.alpha = 1.0})
UIView.animateWithDuration(1.2, animations: { () -> Void in self.d1.alpha = 1.0})
UIView.animateWithDuration(1.3, animations: { () -> Void in self.i.alpha = 1.0})
UIView.animateWithDuration(1.4, animations: { () -> Void in self.o.alpha = 1.0})
UIView.animateWithDuration(1.5, animations: { () -> Void in self.dot.alpha = 1.0})
UIView.animateWithDuration(1.6, animations: { () -> Void in self.h.alpha = 1.0})
UIView.animateWithDuration(1.7, animations: { () -> Void in self.rightarrow.alpha = 1.0})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我觉得必须采用更好的方法(甚至是工作方式)来解决这个问题。
答案 0 :(得分:1)
一种天真的方式就是简单地设置重复计时器。 让计时器从零开始递增Int实例变量。
使用Int值获取邮件的子字符串并将其安装在标签中。当索引达到消息的全长时,终止计时器(或者如果希望文本消失并再次开始绘制,则将Int变量重置为零。)