天道酬勤,学无止境

alamofireimage

在 UITableViewCell 中使用 AlamofireImage(Using AlamofireImage Inside UITableViewCell)

问题 我在这里阅读了很多答案,说通过使用 AlamofireImage 辅助方法(例如af_setImageWithURL() )或任何等效库,您不必担心单元格重用的东西(另外,许多已发布的教程实际上就是这样做的) . 也就是说,在后台下载完成后,我不必保持对单元格的弱引用或使用 tableView 的cellForRowAtIndexPath()方法来更新其 imageView,就像我们通常手动发出请求时所做的那样。 首先,这是真的吗? 如果是这样,它是如何在库中完成的,因为我试图跟踪 AlamofireImage 的af_setImageWithURL()代码,但我找不到任何努力来确保我们仍在处理我们发出请求的同一单元格。 我错过了什么吗? 如果这听起来很愚蠢,我很抱歉,但我真的很困惑。 回答1 假设您正在谈论UIImageView类别,是的,它确实解决了许多困扰幼稚异步图像检索问题的问题,即: 如果在相关单元格的上方或下方插入单元格,则NSIndexPath已更改的事实不会影响相关单元格image的异步更新。 如果您快速滚动到第 100 行,当您在重用单元格上调用af_setImageWithURL时,对先前与此重用单元格关联的先前行的请求将被取消。 这样做的一个含义是,它避免了可见行的图像视图随着对先前与此重用单元关联的行的图像的图像请求而更新。

2022-01-15 07:48:39    分类:技术分享    ios   swift   uitableview   alamofireimage

Using AlamofireImage Inside UITableViewCell

I've been reading a lot of answers here saying that by using AlamofireImage helper methods (e.g. af_setImageWithURL()) or any equivalent library, you don't need to worry about cell reusing stuff (Plus, many published tutorials actually just do that). That is to say, I don't have to keep a weak reference to the cell or getting it by using tableView's cellForRowAtIndexPath() method to update its imageView after the background downloading finishes, like what we usually do if request made manually. First of all, is that true? And if so, how it was done inside the library, cause I tried to trace

2022-01-15 05:17:50    分类:问答    ios   swift   uitableview   alamofireimage

Alamofire 4.0 上传 MultipartFormData 标头(Alamofire 4.0 Upload MultipartFormData Header)

问题 我们如何在Alamofire 4.0的上传功能中添加认证头? 下面是示例代码,但是我认为无法向函数添加标题。 Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(unicornImageURL, withName: "unicorn") multipartFormData.append(rainbowImageURL, withName: "rainbow") }, to: "https://httpbin.org/post", encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in debugPrint(response) } case .failure(let encodingError): print(encodingError) } } ) 之前版本的 alamofire 支持直接添加 header,但新版本不支持。 有任何想法吗? 回答1 我得到了解决方案。 Alamofire.upload(multipartFormData:{

2021-11-30 19:21:49    分类:技术分享    ios   swift   alamofire   swift3   alamofireimage

使用磁盘缓存图像(如果存在于 Alamofire 图像中)(Using disk cached images if present in Alamofire Images)

问题 我正在使用 AlamofireImage 库来缓存下载的图像。 代码: import UIKit import AlamofireImage class ViewController: UIViewController { @IBOutlet weak var firstImageView: UIImageView! @IBOutlet weak var secondImageView: UIImageView! let downloader = ImageDownloader() let URLRequest = NSURLRequest(URL: NSURL(string: "https://httpbin.org/image/jpeg")!) override func viewDidLoad() { super.viewDidLoad() requestFirstImage() } func requestFirstImage() { downloader.downloadImage(URLRequest: URLRequest) { response in print(response.request) print(response.response) debugPrint(response.result) if let image = response

2021-11-30 07:28:03    分类:技术分享    ios   swift   alamofire   alamofireimage

Using disk cached images if present in Alamofire Images

I'm using the AlamofireImage library to cache downloaded images. Code: import UIKit import AlamofireImage class ViewController: UIViewController { @IBOutlet weak var firstImageView: UIImageView! @IBOutlet weak var secondImageView: UIImageView! let downloader = ImageDownloader() let URLRequest = NSURLRequest(URL: NSURL(string: "https://httpbin.org/image/jpeg")!) override func viewDidLoad() { super.viewDidLoad() requestFirstImage() } func requestFirstImage() { downloader.downloadImage(URLRequest: URLRequest) { response in print(response.request) print(response.response) debugPrint(response

2021-11-22 18:17:47    分类:问答    ios   swift   alamofire   alamofireimage

Alamofire 4.0 Upload MultipartFormData Header

How do we add an authentication header to the upload function of Alamofire 4.0? below is the sample code, however I see no way in adding a header to the function. Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(unicornImageURL, withName: "unicorn") multipartFormData.append(rainbowImageURL, withName: "rainbow") }, to: "https://httpbin.org/post", encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload.responseJSON { response in debugPrint(response) } case .failure(let encodingError): print(encodingError) } } )

2021-11-19 03:02:13    分类:问答    ios   swift   alamofire   swift3   alamofireimage

如何使用 af_imageAspectScaled 缩放到所需的像素大小(How to scale to desired size in pixels using af_imageAspectScaled)

问题 我正在使用 AlamoFireImage 裁剪用户个人资料图片,然后再将其发送到服务器。 我们的服务器有一些限制,我们不能发送大于 640x640 的图像。 我正在使用 af_imageAspectScaled UIImage 扩展函数,如下所示: let croppedImage = image.af_imageAspectScaled( toFill: CGSize( width: 320, height: 320 ) ) 我期待这将image裁剪为 320 像素 x 320 像素的图像。 但是我发现输出图像被保存为 640x640px 的图像,比例为 2.0。 以下 XCTest 显示了这一点: class UIImageTests: XCTestCase { func testAfImageAspectScaled() { if let image = UIImage( named: "ipad_mini2_photo_1.JPG", in: Bundle(for: type(of: self)), compatibleWith: nil ) { print (image.scale) // prints 1.0 print (image.size) // prints (1280.0, 960.0) let croppedImage = image.af

2021-10-24 17:09:17    分类:技术分享    ios   swift   alamofireimage

带有 UITableView 单元格的 Swift 4 AlamofireImage(Swift 4 AlamofireImage with UITableView Cell)

问题 我正在使用 AlamofireImages 尝试从服务器下载图像并将其显示在我的表格视图单元格中,这就是我得到的,但我的图像没有出现,只有 textLabel 和 detailTextLabel override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath) print(self.array[indexPath.row]) cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String) cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String) Alamofire.request("http://xxxxxxx.com/uploads/" + (self.array[indexPath.row]["cover"] as! String)).responseImage {

2021-10-23 05:21:01    分类:技术分享    ios   swift   uitableview   alamofire   alamofireimage

How to scale to desired size in pixels using af_imageAspectScaled

I'm using AlamoFireImage to crop an user profile picture before sending it to the server. Our server has some restrictions and we can't send images larger than 640x640. I'm using the af_imageAspectScaled UIImage extension function like so: let croppedImage = image.af_imageAspectScaled( toFill: CGSize( width: 320, height: 320 ) ) I was expecting this to crop image to a 320px by 320px image. However I found out that the output image is being saved as a 640x640px image with scale 2.0. The following XCTest shows this: class UIImageTests: XCTestCase { func testAfImageAspectScaled() { if let image =

2021-10-20 05:23:27    分类:问答    ios   swift   alamofireimage

通过 Swift 3 和 Alamofire 4 上传带有 JSON 和自定义标头的照片/文件 | iOS | 迅速(Upload Photo / File with JSON and custom headers via Swift 3 and Alamofire 4 | iOS | Swift)

问题 我需要使用图像文件和 JSON 调用 Multipart 请求。 我试过这个,但仍然收到错误。 // define parameters let parameters = [ "hometown": "yalikavak", "living": "istanbul" ] Alamofire.upload(multipartFormData: { multipartFormData in if let imageData = UIImageJPEGRepresentation(image, 1) { multipartFormData.append(imageData, withName: "file", fileName: "file.png", mimeType: "image/png") } for (key, value) in parameters { multipartFormData.append((value?.data(using: .utf8))!, withName: key) }}, to: "upload_url", method: .post, headers: ["Authorization": "auth_token"], encodingCompletion: { encodingResult in switch encodingResult

2021-10-16 13:58:15    分类:技术分享    ios   swift   alamofire   multipart   alamofireimage