Swfit5 Kingfisher 5.4.0 手動(dòng)導(dǎo)入支持iOS10以下(iOS8,iOS9)

Kingfisher 最新版本 支持Swift5,但pod要求iOS10以上,

為了支持swfit5, pod 導(dǎo)入的時(shí) 要求最低使用 iOS 10 的系統(tǒng),作者給出理由是iOS10以下的用戶太少,找不到任何理由去支持。太任性了 哈哈!相信依舊給一部分iOS 開發(fā)造成一定的困擾。所以我找到以下方案解決既支持swift5又支持iOS10以下的系統(tǒng),就是本地導(dǎo)入源碼,不通過pod形式。

1.首先先創(chuàng)建一個(gè)新的工程,通過pod 把最新的版本的Kingfisher下載下來,從Pods 文件夾 找到源碼,然后將源碼拖到一個(gè)新的工程中。

2.把源碼進(jìn)行以下的修改,然后運(yùn)行即可。

// MemoryStorage.swfit  75行
cleanTimer = .scheduledTimer(withTimeInterval: config.cleanInterval, repeats: true) { [weak self] _ in
                guard let self = self else { return }
                self.removeExpired()
             }
// 替換如下:
     cleanTimer = Timer.init(timeInterval: config.cleanInterval, target: self, selector: #selector(removeExpiredFunc), userInfo: nil, repeats: true)
          cleanTimer?.fire()  

并且在該類添加一個(gè)方法
 @objc func removeExpiredFunc()  {
        self.removeExpired()
      }        
     
// ImageModifier.swift  里面 96行
return image.imageFlippedForRightToLeftLayoutDirection()  
// 替換如下:
if #available(iOS 9.0, *) {
        return image.imageFlippedForRightToLeftLayoutDirection()
      } else {
        return image
      }
// ImageView+Kingfisher.swift  343行
view.centerXAnchor.constraint(
                    equalTo: base.centerXAnchor, constant: newIndicator.centerOffset.x).isActive = true
 view.centerYAnchor.constraint(
                    equalTo: base.centerYAnchor, constant: newIndicator.centerOffset.y).isActive = true
// 替換如下:
 if #available(iOS 9.0, *) {
                view.centerXAnchor.constraint(
                  equalTo: base.centerXAnchor, constant: newIndicator.centerOffset.x).isActive = true
                view.centerYAnchor.constraint(
                  equalTo: base.centerYAnchor, constant: newIndicator.centerOffset.y).isActive = true
              } else {
                // Fallback on earlier versions
                NSLayoutConstraint.activate([
                  NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: base, attribute: .centerX, multiplier: 1, constant: newIndicator.centerOffset.x),
                  NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: base, attribute: .centerY, multiplier: 1, constant: newIndicator.centerOffset.y),
                  
                  ])
              }
// Placeholder.swift 66行
centerXAnchor.constraint(equalTo: imageView.centerXAnchor).isActive = true
        centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
        heightAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
        widthAnchor.constraint(equalTo: imageView.widthAnchor).isActive = true
// 替換入下:
if #available(iOS 9.0, *) {
        centerXAnchor.constraint(equalTo: imageView.centerXAnchor).isActive = true
        centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
        heightAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
        widthAnchor.constraint(equalTo: imageView.widthAnchor).isActive = true
      } else {
        // Fallback on earlier versions
        NSLayoutConstraint.activate([
          NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: imageView, attribute: .centerX, multiplier: 1, constant: 0),
          NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: imageView, attribute: .centerY, multiplier: 1, constant: 0),
          NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: imageView, attribute: .height, multiplier: 1, constant: 0),
          NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: imageView, attribute: .width, multiplier: 1, constant: 0)
          ])
      }
// AnimatableImageView.swift 289行
if displayLink.preferredFramesPerSecond == 0 {
            duration = displayLink.duration
        } else {
            // Some devices (like iPad Pro 10.5) will have a different FPS.
            duration = 1.0 / Double(displayLink.preferredFramesPerSecond)
        }

// 替換如下:
 if #available(iOS 10.0, *) {
        if displayLink.preferredFramesPerSecond == 0 {
          duration = displayLink.duration
        } else {
          // Some devices (like iPad Pro 10.5) will have a different FPS.
          duration = 1.0 / Double(displayLink.preferredFramesPerSecond)
        }
      } else {
        duration = displayLink.duration
      }

PS:然后運(yùn)行即可,有問題歡迎留言。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容