import UIKit import Kingfisher class KingfisherViewController: UIViewController { let url = "http://img3.cache.netease.com/game/2014/7/2/20140702132129bebcf.jpg" @IBOutlet weak var loadedIamgeView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } /* //MARK: - 基本用法 */ @IBAction func request(sender: UIButton) { requestimage4() } /* //MARK: - 基本用法 */ func request0() -> Void{ self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!) //带有默认图片的用法 self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!,placeholderImage: nil) } /* //MARK: - Kingfisher是带有缓存的,在请求之前会在(内存或者硬盘)找此图片,如果没有才会发起网络请求 如果你想每次都是从网络加载的图片,可以在一个参数字典中设置一下,让请求忽略点缓存 */ func requestimage1() -> Void{ self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!,placeholderImage: nil,optionsInfo:[.Options(KingfisherOptions.ForceRefresh)]) } /* //MARK: - 请求下图片来后,会有一定时间的渐变 慢慢显示在ImageView上面 */ func requestimage2() -> Void{ self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!,optionsInfo: [.Transition(ImageTransition.Fade(1))]) } /* //MARK: - 擦 怎么进度打印不出来啊 只能得到image、缓存类型、和image的地址 */ func requestimage3() -> Void{ self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!,optionsInfo: nil,progressBlock: { (receivedSize,totalSize) -> () in dispatch_async(dispatch_get_main_queue(),{ () -> Void in print("receive\(totalSize)") }) }) { (image,error,cacheType,imageURL) -> () in print(image?.size.width) } } func requestimage4() -> Void{ //kf_setimageWithURL 每个方法都会返回一个RetrieveImageTask的对象,可以调用cancel方法取消下载图片 let task = self.loadedIamgeView.kf_setimageWithURL(NSURL(string: url)!) task.cancel() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application,you will often want to do a little preparation before navigation override func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }