美文网首页
UIImageView

UIImageView

作者: CaptainRoy | 来源:发表于2019-08-18 15:23 被阅读0次
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()
    }
}

相关文章

网友评论

      本文标题:UIImageView

      本文链接:https://www.haomeiwen.com/subject/sjirsctx.html