2 // ImageTransition.swift
5 // Created by Wei Wang on 15/9/18.
7 // Copyright (c) 2018 Wei Wang <onevcat@gmail.com>
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 // Not implemented for macOS and watchOS yet.
32 /// Image transition is not supported on macOS.
33 public enum ImageTransition {
35 var duration: TimeInterval {
42 /// Image transition is not supported on watchOS.
43 public enum ImageTransition {
45 var duration: TimeInterval {
53 Transition effect which will be used when an image downloaded and set by `UIImageView` extension API in Kingfisher.
54 You can assign an enum value with transition duration as an item in `KingfisherOptionsInfo`
55 to enable the animation transition.
57 Apple's UIViewAnimationOptions is used under the hood.
58 For custom transition, you should specified your own transition options, animations and
59 comletion handler as well.
61 public enum ImageTransition {
62 /// No animation transistion.
65 /// Fade in the loaded image.
66 case fade(TimeInterval)
68 /// Flip from left transition.
69 case flipFromLeft(TimeInterval)
71 /// Flip from right transition.
72 case flipFromRight(TimeInterval)
74 /// Flip from top transition.
75 case flipFromTop(TimeInterval)
77 /// Flip from bottom transition.
78 case flipFromBottom(TimeInterval)
80 /// Custom transition.
81 case custom(duration: TimeInterval,
82 options: UIViewAnimationOptions,
83 animations: ((UIImageView, UIImage) -> Void)?,
84 completion: ((Bool) -> Void)?)
86 var duration: TimeInterval {
89 case .fade(let duration): return duration
91 case .flipFromLeft(let duration): return duration
92 case .flipFromRight(let duration): return duration
93 case .flipFromTop(let duration): return duration
94 case .flipFromBottom(let duration): return duration
96 case .custom(let duration, _, _, _): return duration
100 var animationOptions: UIViewAnimationOptions {
102 case .none: return []
103 case .fade(_): return .transitionCrossDissolve
105 case .flipFromLeft(_): return .transitionFlipFromLeft
106 case .flipFromRight(_): return .transitionFlipFromRight
107 case .flipFromTop(_): return .transitionFlipFromTop
108 case .flipFromBottom(_): return .transitionFlipFromBottom
110 case .custom(_, let options, _, _): return options
114 var animations: ((UIImageView, UIImage) -> Void)? {
116 case .custom(_, _, let animations, _): return animations
117 default: return { $0.image = $1 }
121 var completion: ((Bool) -> Void)? {
123 case .custom(_, _, _, let completion): return completion