SDWebImageTransition.h 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDWebImageCompat.h"
  9. #if SD_UIKIT || SD_MAC
  10. #import "SDImageCache.h"
  11. // This class is used to provide a transition animation after the view category load image finished. Use this on `sd_imageTransition` in UIView+WebCache.h
  12. // for UIKit(iOS & tvOS), we use `+[UIView transitionWithView:duration:options:animations:completion]` for transition animation.
  13. // for AppKit(macOS), we use `+[NSAnimationContext runAnimationGroup:completionHandler:]` for transition animation. You can call `+[NSAnimationContext currentContext]` to grab the context during animations block.
  14. // These transition are provided for basic usage. If you need complicated animation, consider to directly use Core Animation or use `SDWebImageAvoidAutoSetImage` and implement your own after image load finished.
  15. #if SD_UIKIT
  16. typedef UIViewAnimationOptions SDWebImageAnimationOptions;
  17. #else
  18. typedef NS_OPTIONS(NSUInteger, SDWebImageAnimationOptions) {
  19. SDWebImageAnimationOptionAllowsImplicitAnimation = 1 << 0, // specify `allowsImplicitAnimation` for the `NSAnimationContext`
  20. };
  21. #endif
  22. typedef void (^SDWebImageTransitionPreparesBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image, NSData * _Nullable imageData, SDImageCacheType cacheType, NSURL * _Nullable imageURL);
  23. typedef void (^SDWebImageTransitionAnimationsBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image);
  24. typedef void (^SDWebImageTransitionCompletionBlock)(BOOL finished);
  25. @interface SDWebImageTransition : NSObject
  26. /**
  27. By default, we set the image to the view at the beginning of the animtions. You can disable this and provide custom set image process
  28. */
  29. @property (nonatomic, assign) BOOL avoidAutoSetImage;
  30. /**
  31. The duration of the transition animation, measured in seconds. Defaults to 0.5.
  32. */
  33. @property (nonatomic, assign) NSTimeInterval duration;
  34. /**
  35. The timing function used for all animations within this transition animation (macOS).
  36. */
  37. @property (nonatomic, strong, nullable) CAMediaTimingFunction *timingFunction NS_AVAILABLE_MAC(10_7);
  38. /**
  39. A mask of options indicating how you want to perform the animations.
  40. */
  41. @property (nonatomic, assign) SDWebImageAnimationOptions animationOptions;
  42. /**
  43. A block object to be executed before the animation sequence starts.
  44. */
  45. @property (nonatomic, copy, nullable) SDWebImageTransitionPreparesBlock prepares;
  46. /**
  47. A block object that contains the changes you want to make to the specified view.
  48. */
  49. @property (nonatomic, copy, nullable) SDWebImageTransitionAnimationsBlock animations;
  50. /**
  51. A block object to be executed when the animation sequence ends.
  52. */
  53. @property (nonatomic, copy, nullable) SDWebImageTransitionCompletionBlock completion;
  54. @end
  55. // Convenience way to create transition. Remember to specify the duration if needed.
  56. // for UIKit, these transition just use the correspond `animationOptions`. By default we enable `UIViewAnimationOptionAllowUserInteraction` to allow user interaction during transition.
  57. // for AppKit, these transition use Core Animation in `animations`. So your view must be layer-backed. Set `wantsLayer = YES` before you apply it.
  58. @interface SDWebImageTransition (Conveniences)
  59. // class property is available in Xcode 8. We will drop the Xcode 7.3 support in 5.x
  60. #if __has_feature(objc_class_property)
  61. /// Fade transition.
  62. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *fadeTransition;
  63. /// Flip from left transition.
  64. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *flipFromLeftTransition;
  65. /// Flip from right transition.
  66. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *flipFromRightTransition;
  67. /// Flip from top transition.
  68. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *flipFromTopTransition;
  69. /// Flip from bottom transition.
  70. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *flipFromBottomTransition;
  71. /// Curl up transition.
  72. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *curlUpTransition;
  73. /// Curl down transition.
  74. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *curlDownTransition;
  75. #else
  76. + (nonnull instancetype)fadeTransition;
  77. + (nonnull instancetype)flipFromLeftTransition;
  78. + (nonnull instancetype)flipFromRightTransition;
  79. + (nonnull instancetype)flipFromTopTransition;
  80. + (nonnull instancetype)flipFromBottomTransition;
  81. + (nonnull instancetype)curlUpTransition;
  82. + (nonnull instancetype)curlDownTransition;
  83. #endif
  84. @end
  85. #endif