SDWebImageTransition.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "SDWebImageTransition.h"
  9. #if SD_UIKIT || SD_MAC
  10. #if SD_MAC
  11. #import <QuartzCore/QuartzCore.h>
  12. #endif
  13. @implementation SDWebImageTransition
  14. - (instancetype)init {
  15. self = [super init];
  16. if (self) {
  17. self.duration = 0.5;
  18. }
  19. return self;
  20. }
  21. @end
  22. @implementation SDWebImageTransition (Conveniences)
  23. + (SDWebImageTransition *)fadeTransition {
  24. SDWebImageTransition *transition = [SDWebImageTransition new];
  25. #if SD_UIKIT
  26. transition.animationOptions = UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction;
  27. #else
  28. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  29. CATransition *trans = [CATransition animation];
  30. trans.type = kCATransitionFade;
  31. [view.layer addAnimation:trans forKey:kCATransition];
  32. };
  33. #endif
  34. return transition;
  35. }
  36. + (SDWebImageTransition *)flipFromLeftTransition {
  37. SDWebImageTransition *transition = [SDWebImageTransition new];
  38. #if SD_UIKIT
  39. transition.animationOptions = UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowUserInteraction;
  40. #else
  41. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  42. CATransition *trans = [CATransition animation];
  43. trans.type = kCATransitionPush;
  44. trans.subtype = kCATransitionFromLeft;
  45. [view.layer addAnimation:trans forKey:kCATransition];
  46. };
  47. #endif
  48. return transition;
  49. }
  50. + (SDWebImageTransition *)flipFromRightTransition {
  51. SDWebImageTransition *transition = [SDWebImageTransition new];
  52. #if SD_UIKIT
  53. transition.animationOptions = UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionAllowUserInteraction;
  54. #else
  55. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  56. CATransition *trans = [CATransition animation];
  57. trans.type = kCATransitionPush;
  58. trans.subtype = kCATransitionFromRight;
  59. [view.layer addAnimation:trans forKey:kCATransition];
  60. };
  61. #endif
  62. return transition;
  63. }
  64. + (SDWebImageTransition *)flipFromTopTransition {
  65. SDWebImageTransition *transition = [SDWebImageTransition new];
  66. #if SD_UIKIT
  67. transition.animationOptions = UIViewAnimationOptionTransitionFlipFromTop | UIViewAnimationOptionAllowUserInteraction;
  68. #else
  69. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  70. CATransition *trans = [CATransition animation];
  71. trans.type = kCATransitionPush;
  72. trans.subtype = kCATransitionFromTop;
  73. [view.layer addAnimation:trans forKey:kCATransition];
  74. };
  75. #endif
  76. return transition;
  77. }
  78. + (SDWebImageTransition *)flipFromBottomTransition {
  79. SDWebImageTransition *transition = [SDWebImageTransition new];
  80. #if SD_UIKIT
  81. transition.animationOptions = UIViewAnimationOptionTransitionFlipFromBottom | UIViewAnimationOptionAllowUserInteraction;
  82. #else
  83. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  84. CATransition *trans = [CATransition animation];
  85. trans.type = kCATransitionPush;
  86. trans.subtype = kCATransitionFromBottom;
  87. [view.layer addAnimation:trans forKey:kCATransition];
  88. };
  89. #endif
  90. return transition;
  91. }
  92. + (SDWebImageTransition *)curlUpTransition {
  93. SDWebImageTransition *transition = [SDWebImageTransition new];
  94. #if SD_UIKIT
  95. transition.animationOptions = UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionAllowUserInteraction;
  96. #else
  97. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  98. CATransition *trans = [CATransition animation];
  99. trans.type = kCATransitionReveal;
  100. trans.subtype = kCATransitionFromTop;
  101. [view.layer addAnimation:trans forKey:kCATransition];
  102. };
  103. #endif
  104. return transition;
  105. }
  106. + (SDWebImageTransition *)curlDownTransition {
  107. SDWebImageTransition *transition = [SDWebImageTransition new];
  108. #if SD_UIKIT
  109. transition.animationOptions = UIViewAnimationOptionTransitionCurlDown | UIViewAnimationOptionAllowUserInteraction;
  110. #else
  111. transition.animations = ^(__kindof NSView * _Nonnull view, NSImage * _Nullable image) {
  112. CATransition *trans = [CATransition animation];
  113. trans.type = kCATransitionReveal;
  114. trans.subtype = kCATransitionFromBottom;
  115. [view.layer addAnimation:trans forKey:kCATransition];
  116. };
  117. #endif
  118. return transition;
  119. }
  120. @end
  121. #endif