小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(五)Image View视图 学习笔记

 留下两个问题:1、后面涉及到的异常不知道原因。2、动态图片到了程序里面就不动了。

 

 

 

 
 
 
然后:
 
上面是有问题的,下面是没有问题的了。
 
 代码(另外简单写的代码,纠正了那个错误):
 1 import UIKit
 2 
 3 class ViewController: UIViewController{
 4     
 5     @IBOutlet weak var imageView: UIImageView!
 6     @IBAction func button(sender: UIButton) {
 7         imageView.animationImages = [UIImage(named: "p1")!,UIImage(named: "p2")!,UIImage(named: "p3")!,UIImage(named: "p4")!,UIImage(named: "p5")!]
 8         imageView.contentMode = .ScaleAspectFit
 9         imageView.animationDuration = 10
10         imageView.startAnimating()
11         
12     }
13     override func viewDidLoad() {
14         super.viewDidLoad()
15         
16     }
17 
18     override func didReceiveMemoryWarning() {
19         super.didReceiveMemoryWarning()
20     }
21 }

根据小波老师改进后的方法(如果有100张,如果一张一张添加创建对象,就不好了):

 1 import UIKit
 2 
 3 class ViewController: UIViewController{
 4     
 5     @IBOutlet weak var imageView: UIImageView!
 6     @IBAction func button(sender: UIButton) {
 7 //        imageView.animationImages = [UIImage(named: "p1")!,UIImage(named: "p2")!,UIImage(named: "p3")!,UIImage(named: "p4")!,UIImage(named: "p5")!]
 8         imageView.animationImages = (1...5).map{
 9             UIImage(named: "p\($0)")!
10         }
11         imageView.contentMode = .ScaleAspectFit
12         imageView.animationDuration = 10
13         imageView.startAnimating()
14         
15     }
16     override func viewDidLoad() {
17         super.viewDidLoad()
18         
19     }
20 
21     override func didReceiveMemoryWarning() {
22         super.didReceiveMemoryWarning()
23     }
24 }

 

 
 
 
 
 
posted @ 2015-07-21 14:16  何杨  阅读(263)  评论(0编辑  收藏  举报