Kingfisher 最新版本 支持Swift5,但pod要求iOS10以上,
为了支持swfit5, pod 导入的时 要求最低使用 iOS 10 的系统,作者给出理由是iOS10以下的用户太少,找不到任何理由去支持。太任性了 哈哈!相信依旧给一部分iOS 开发造成一定的困扰。所以我找到以下方案解决既支持swift5又支持iOS10以下的系统,就是本地导入源码,不通过pod形式。
1.首先先创建一个新的工程,通过pod 把最新的版本的Kingfisher下载下来,从Pods 文件夹 找到源码,然后将源码拖到一个新的工程中。
2.把源码进行以下的修改,然后运行即可。
// 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()
并且在该类添加一个方法
@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:然后运行即可,有问题欢迎留言。
网友评论