Pārlūkot izejas kodu

Add force transition option

onevcat 9 gadi atpakaļ
vecāks
revīzija
29bfa14541

+ 2 - 2
Sources/ImageView+Kingfisher.swift

@@ -129,8 +129,8 @@ extension ImageView {
                         return
                     }
                     
-                    if let transitionItem = optionsInfo?.kf_firstMatchIgnoringAssociatedValue(.Transition(.None)),
-                        case .Transition(let transition) = transitionItem where cacheType == .None {
+                    if let transitionItem = options.kf_firstMatchIgnoringAssociatedValue(.Transition(.None)),
+                        case .Transition(let transition) = transitionItem where ( options.forceTransition || cacheType == .None) {
                             #if !os(OSX)
                                 UIView.transitionWithView(sSelf, duration: 0.0, options: [],
                                     animations: {

+ 8 - 1
Sources/KingfisherOptionsInfo.swift

@@ -42,9 +42,10 @@ Items could be added into KingfisherOptionsInfo.
 
 - TargetCache: The associated value of this member should be an ImageCache object. Kingfisher will use the specified cache object when handling related operations, including trying to retrieve the cached images and store the downloaded image to it.
 - Downloader:  The associated value of this member should be an ImageDownloader object. Kingfisher will use this downloader to download the images.
-- Transition:  Member for animation transition when using UIImageView. Kingfisher will use the `ImageTransition` of this enum to animate the image in if it is downloaded from web. The transition will not happen when the image is retrieved from either memory or disk cache.
+- Transition:  Member for animation transition when using UIImageView. Kingfisher will use the `ImageTransition` of this enum to animate the image in if it is downloaded from web. The transition will not happen when the image is retrieved from either memory or disk cache by default. If you need to do the transition even when the image being retrieved from cache, set `ForceTransition` as well.
 - DownloadPriority: Associated `Float` value will be set as the priority of image download task. The value for it should be between 0.0~1.0. If this option not set, the default value (`NSURLSessionTaskPriorityDefault`) will be used.
 - ForceRefresh: If set, `Kingfisher` will ignore the cache and try to fire a download task for the resource.
+- ForceTransition: If set, setting the image to an image view will happen with transition even when retrieved from cache. See `Transition` option for more.
 - CacheMemoryOnly: If set, `Kingfisher` will only cache the value in memory but not in disk.
 - BackgroundDecode: Decode the image in background thread before using.
 - CallbackDispatchQueue: The associated value of this member will be used as the target queue of dispatch callbacks when retrieving images from cache. If not set, `Kingfisher` will use main quese for callbacks.
@@ -57,6 +58,7 @@ public enum KingfisherOptionsInfoItem {
     case Transition(ImageTransition)
     case DownloadPriority(Float)
     case ForceRefresh
+    case ForceTransition
     case CacheMemoryOnly
     case BackgroundDecode
     case CallbackDispatchQueue(dispatch_queue_t?)
@@ -77,6 +79,7 @@ func <== (lhs: KingfisherOptionsInfoItem, rhs: KingfisherOptionsInfoItem) -> Boo
     case (.Transition(_), .Transition(_)): fallthrough
     case (.DownloadPriority(_), .DownloadPriority(_)): fallthrough
     case (.ForceRefresh, .ForceRefresh): fallthrough
+    case (.ForceTransition, .ForceTransition): fallthrough
     case (.CacheMemoryOnly, .CacheMemoryOnly): fallthrough
     case (.BackgroundDecode, .BackgroundDecode): fallthrough
     case (.CallbackDispatchQueue(_), .CallbackDispatchQueue(_)): fallthrough
@@ -138,6 +141,10 @@ extension CollectionType where Generator.Element == KingfisherOptionsInfoItem {
         return contains{ $0 <== .ForceRefresh }
     }
     
+    var forceTransition: Bool {
+        return contains{ $0 <== .ForceTransition }
+    }
+    
     var cacheMemoryOnly: Bool {
         return contains{ $0 <== .CacheMemoryOnly }
     }