[英]Animation not animating in Swift 3 Xcode 8.1
When I run my application with the following code it only displays the first frame and doesn't loop through the other images. 当我使用以下代码运行我的应用程序时,它只显示第一帧,而不是循环其他图像。
class ViewController: UIViewController, UITextFieldDelegate {
var signUpMode = true
var activityIndicator = UIActivityIndicatorView()
@IBOutlet weak var emailText: UITextField!
@IBOutlet weak var passwordText: UITextField!
@IBOutlet weak var signIn: UIImageView!
//Animated sign in
var counter = 0
var animationStart = false
var timer = Timer()
func animateSignIn() {
signIn.image = UIImage(named: "frame_\(counter)_delay-0.04s.gif")
counter += 1
if counter == 128 {
counter = 0
}
}
func animation (){
if animationStart == true {
timer = Timer.scheduledTimer(timeInterval: 0.04, target: self, selector: #selector(ViewController.animateSignIn), userInfo: nil, repeats: true)
}
}
Then I set animationStart
to true
: 然后我将animationStart
设置为true
:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//remove root view controller navigation bar
self.navigationController?.navigationBar.isHidden = true
animationStart = true
}
Where did you call the function animation()
? 你在哪里调用函数animation()
?
I think viewDidLoad
should look like this 我认为viewDidLoad
应该是这样的
override func viewDidLoad() {
super.viewDidLoad()
//remove root view controller navigation bar
self.navigationController?.navigationBar.isHidden = true
animationStart = true
animation() //call animation
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.