BU_SDWebImageTransition.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "BU_SDWebImageCompat.h"
  9. #if SD_UIKIT || SD_MAC
  10. #import "BU_SDImageCache.h"
  11. #if SD_UIKIT
  12. typedef UIViewAnimationOptions SDWebImageAnimationOptions;
  13. #else
  14. typedef NS_OPTIONS(NSUInteger, SDWebImageAnimationOptions) {
  15. SDWebImageAnimationOptionAllowsImplicitAnimation = 1 << 0, // specify `allowsImplicitAnimation` for the `NSAnimationContext`
  16. };
  17. #endif
  18. typedef void (^SDWebImageTransitionPreparesBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image, NSData * _Nullable imageData, BU_SDImageCacheType cacheType, NSURL * _Nullable imageURL);
  19. typedef void (^SDWebImageTransitionAnimationsBlock)(__kindof UIView * _Nonnull view, UIImage * _Nullable image);
  20. typedef void (^SDWebImageTransitionCompletionBlock)(BOOL finished);
  21. /**
  22. This class is used to provide a transition animation after the view category load image finished. Use this on `sdBu_imageTransition` in UIView+BU_WebCache.h
  23. for UIKit(iOS & tvOS), we use `+[UIView transitionWithView:duration:options:animations:completion]` for transition animation.
  24. for AppKit(macOS), we use `+[NSAnimationContext runAnimationGroup:completionHandler:]` for transition animation. You can call `+[NSAnimationContext currentContext]` to grab the context during animations block.
  25. @note 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.
  26. */
  27. @interface BU_SDWebImageTransition : NSObject
  28. /**
  29. 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
  30. */
  31. @property (nonatomic, assign) BOOL avoidAutoSetImage;
  32. /**
  33. The duration of the transition animation, measured in seconds. Defaults to 0.5.
  34. */
  35. @property (nonatomic, assign) NSTimeInterval duration;
  36. /**
  37. The timing function used for all animations within this transition animation (macOS).
  38. */
  39. @property (nonatomic, strong, nullable) CAMediaTimingFunction *timingFunction API_UNAVAILABLE(ios, tvos, watchos);
  40. /**
  41. A mask of options indicating how you want to perform the animations.
  42. */
  43. @property (nonatomic, assign) SDWebImageAnimationOptions animationOptions;
  44. /**
  45. A block object to be executed before the animation sequence starts.
  46. */
  47. @property (nonatomic, copy, nullable) SDWebImageTransitionPreparesBlock prepares;
  48. /**
  49. A block object that contains the changes you want to make to the specified view.
  50. */
  51. @property (nonatomic, copy, nullable) SDWebImageTransitionAnimationsBlock animations;
  52. /**
  53. A block object to be executed when the animation sequence ends.
  54. */
  55. @property (nonatomic, copy, nullable) SDWebImageTransitionCompletionBlock completion;
  56. @end
  57. /**
  58. Convenience way to create transition. Remember to specify the duration if needed.
  59. for UIKit, these transition just use the correspond `animationOptions`. By default we enable `UIViewAnimationOptionAllowUserInteraction` to allow user interaction during transition.
  60. for AppKit, these transition use Core Animation in `animations`. So your view must be layer-backed. Set `wantsLayer = YES` before you apply it.
  61. */
  62. //@interface BU_SDWebImageTransition (Conveniences)
  63. //
  64. ///// Fade transition.
  65. ////@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *fadeTransition;
  66. ///// Flip from left transition.
  67. ////@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *flipFromLeftTransition;
  68. ///// Flip from right transition.
  69. //@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *flipFromRightTransition;
  70. ///// Flip from top transition.
  71. //@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *flipFromTopTransition;
  72. ///// Flip from bottom transition.
  73. //@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *flipFromBottomTransition;
  74. ///// Curl up transition.
  75. //@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *curlUpTransition;
  76. ///// Curl down transition.
  77. //@property (nonatomic, class, nonnull, readonly) BU_SDWebImageTransition *curlDownTransition;
  78. //
  79. //@end
  80. #endif