class ViewController: UIViewController,UITextFieldDelegate {
var imageView:UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let path1 = Bundle.main.path(forResource:"christmas", ofType: "jpg")
let image1 = UIImage(contentsOfFile: path1!)
let path2 = Bundle.main.path(forResource:"image", ofType: "jpg")
let image2 = UIImage(contentsOfFile: path2!)
imageView = UIImageView(frame: CGRect(x: 10.0, y: 40.0, width: 100.0, height: 100.0))
imageView.backgroundColor = UIColor.red
imageView.animationImages = [image1!,image2!]
imageView.animationDuration = 1.0
self.view.addSubview(imageView)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
imageView.startAnimating()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
imageView.stopAnimating()
}
}
网友评论