FTAnimation+UIView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. The MIT License
  3. Copyright (c) 2009 Free Time Studios and Nathan Eror
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #import "FTAnimation+UIView.h"
  21. #import "FTUtils.h"
  22. #import "FTUtils+NSObject.h"
  23. @implementation UIView (FTAnimationAdditions)
  24. #pragma mark - Sliding Animations
  25. - (void)slideInFrom:(FTAnimationDirection)direction duration:(NSTimeInterval)duration delegate:(id)delegate
  26. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  27. CAAnimation *slideInAnim = [[FTAnimationManager sharedManager] slideInAnimationFor:self direction:direction
  28. duration:duration delegate:delegate
  29. startSelector:startSelector stopSelector:stopSelector];
  30. [self.layer addAnimation:slideInAnim forKey:kFTAnimationSlideIn];
  31. }
  32. - (void)slideInFrom:(FTAnimationDirection)direction duration:(NSTimeInterval)duration delegate:(id)delegate {
  33. [self slideInFrom:direction duration:duration delegate:delegate startSelector:nil stopSelector:nil];
  34. }
  35. - (void)slideOutTo:(FTAnimationDirection)direction duration:(NSTimeInterval)duration
  36. delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  37. CAAnimation *slideOutAnim = [[FTAnimationManager sharedManager] slideOutAnimationFor:self direction:direction
  38. duration:duration delegate:delegate
  39. startSelector:startSelector stopSelector:stopSelector];
  40. [self.layer addAnimation:slideOutAnim forKey:kFTAnimationSlideOut];
  41. }
  42. - (void)slideOutTo:(FTAnimationDirection)direction duration:(NSTimeInterval)duration delegate:(id)delegate {
  43. [self slideOutTo:direction duration:duration delegate:delegate startSelector:nil stopSelector:nil];
  44. }
  45. - (void)slideInFrom:(FTAnimationDirection)direction inView:(UIView*)enclosingView duration:(NSTimeInterval)duration delegate:(id)delegate
  46. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  47. CAAnimation *slideInAnim = [[FTAnimationManager sharedManager] slideInAnimationFor:self direction:direction inView:(UIView*)enclosingView
  48. duration:duration delegate:delegate
  49. startSelector:startSelector stopSelector:stopSelector];
  50. [self.layer addAnimation:slideInAnim forKey:kFTAnimationSlideIn];
  51. }
  52. - (void)slideOutTo:(FTAnimationDirection)direction inView:(UIView*)enclosingView duration:(NSTimeInterval)duration
  53. delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  54. CAAnimation *slideOutAnim = [[FTAnimationManager sharedManager] slideOutAnimationFor:self direction:direction inView:(UIView*)enclosingView
  55. duration:duration delegate:delegate
  56. startSelector:startSelector stopSelector:stopSelector];
  57. [self.layer addAnimation:slideOutAnim forKey:kFTAnimationSlideOut];
  58. }
  59. #pragma mark - Back In/Out Animations
  60. - (void)backOutTo:(FTAnimationDirection)direction withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate
  61. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  62. CAAnimation *backOutAnim = [[FTAnimationManager sharedManager] backOutAnimationFor:self withFade:fade direction:direction
  63. duration:duration delegate:delegate
  64. startSelector:startSelector stopSelector:stopSelector];
  65. [self.layer addAnimation:backOutAnim forKey:kFTAnimationBackOut];
  66. }
  67. - (void)backOutTo:(FTAnimationDirection)direction withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate {
  68. [self backOutTo:direction withFade:fade duration:duration delegate:delegate startSelector:nil stopSelector:nil];
  69. }
  70. - (void)backInFrom:(FTAnimationDirection)direction withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate
  71. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  72. CAAnimation *backInAnim = [[FTAnimationManager sharedManager] backInAnimationFor:self withFade:fade direction:direction
  73. duration:duration delegate:delegate
  74. startSelector:startSelector stopSelector:stopSelector];
  75. [self.layer addAnimation:backInAnim forKey:kFTAnimationBackIn];
  76. }
  77. - (void)backInFrom:(FTAnimationDirection)direction withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate {
  78. [self backInFrom:direction withFade:fade duration:duration delegate:delegate startSelector:nil stopSelector:nil];
  79. }
  80. - (void)backOutTo:(FTAnimationDirection)direction inView:(UIView*)enclosingView withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate
  81. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  82. CAAnimation *backOutAnim = [[FTAnimationManager sharedManager] backOutAnimationFor:self withFade:fade direction:direction inView:enclosingView
  83. duration:duration delegate:delegate
  84. startSelector:startSelector stopSelector:stopSelector];
  85. [self.layer addAnimation:backOutAnim forKey:kFTAnimationBackOut];
  86. }
  87. - (void)backInFrom:(FTAnimationDirection)direction inView:(UIView*)enclosingView withFade:(BOOL)fade duration:(NSTimeInterval)duration delegate:(id)delegate
  88. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  89. CAAnimation *backInAnim = [[FTAnimationManager sharedManager] backInAnimationFor:self withFade:fade direction:direction inView:enclosingView
  90. duration:duration delegate:delegate
  91. startSelector:startSelector stopSelector:stopSelector];
  92. [self.layer addAnimation:backInAnim forKey:kFTAnimationBackIn];
  93. }
  94. #pragma mark - Fade Animations
  95. - (void)fadeIn:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  96. CAAnimation *anim = [[FTAnimationManager sharedManager] fadeAnimationFor:self duration:duration delegate:delegate
  97. startSelector:startSelector stopSelector:stopSelector fadeOut:NO];
  98. [self.layer addAnimation:anim forKey:kFTAnimationFadeIn];
  99. }
  100. - (void)fadeIn:(NSTimeInterval)duration delegate:(id)delegate {
  101. [self fadeIn:duration delegate:delegate startSelector:nil stopSelector:nil];
  102. }
  103. - (void)fadeOut:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  104. CAAnimation *anim = [[FTAnimationManager sharedManager] fadeAnimationFor:self duration:duration delegate:delegate
  105. startSelector:startSelector stopSelector:stopSelector fadeOut:YES];
  106. [self.layer addAnimation:anim forKey:kFTAnimationFadeOut];
  107. }
  108. - (void)fadeOut:(NSTimeInterval)duration delegate:(id)delegate {
  109. [self fadeOut:duration delegate:delegate startSelector:nil stopSelector:nil];
  110. }
  111. - (void)fadeBackgroundColorIn:(NSTimeInterval)duration delegate:(id)delegate
  112. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  113. CAAnimation *anim = [[FTAnimationManager sharedManager] fadeBackgroundColorAnimationFor:self duration:duration
  114. delegate:delegate startSelector:startSelector
  115. stopSelector:stopSelector fadeOut:NO];
  116. [self.layer addAnimation:anim forKey:kFTAnimationFadeBackgroundIn];
  117. }
  118. - (void)fadeBackgroundColorIn:(NSTimeInterval)duration delegate:(id)delegate {
  119. [self fadeBackgroundColorIn:duration delegate:delegate startSelector:nil stopSelector:nil];
  120. }
  121. - (void)fadeBackgroundColorOut:(NSTimeInterval)duration delegate:(id)delegate
  122. startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  123. CAAnimation *anim = [[FTAnimationManager sharedManager] fadeBackgroundColorAnimationFor:self duration:duration
  124. delegate:delegate startSelector:startSelector
  125. stopSelector:stopSelector fadeOut:YES];
  126. [self.layer addAnimation:anim forKey:kFTAnimationFadeBackgroundOut];
  127. }
  128. - (void)fadeBackgroundColorOut:(NSTimeInterval)duration delegate:(id)delegate {
  129. [self fadeBackgroundColorOut:duration delegate:delegate startSelector:nil stopSelector:nil];
  130. }
  131. #pragma mark - Popping Animations
  132. - (void)popIn:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  133. CAAnimation *anim = [[FTAnimationManager sharedManager] popInAnimationFor:self duration:duration delegate:delegate
  134. startSelector:startSelector stopSelector:stopSelector];
  135. [self.layer addAnimation:anim forKey:kFTAnimationPopIn];
  136. }
  137. - (void)popIn:(NSTimeInterval)duration delegate:(id)delegate {
  138. [self popIn:duration delegate:delegate startSelector:nil stopSelector:nil];
  139. }
  140. - (void)popOut:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  141. CAAnimation *anim = [[FTAnimationManager sharedManager] popOutAnimationFor:self duration:duration delegate:delegate
  142. startSelector:startSelector stopSelector:stopSelector];
  143. [self.layer addAnimation:anim forKey:kFTAnimationPopOut];
  144. }
  145. - (void)popOut:(NSTimeInterval)duration delegate:(id)delegate {
  146. [self popOut:duration delegate:delegate startSelector:nil stopSelector:nil];
  147. }
  148. #pragma mark - Fall In and Fly Out
  149. - (void)fallIn:(NSTimeInterval)duration delegate:(id)delegate {
  150. [self fallIn:duration delegate:delegate startSelector:nil stopSelector:nil];
  151. }
  152. - (void)fallIn:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  153. CAAnimation *anim = [[FTAnimationManager sharedManager] fallInAnimationFor:self duration:duration delegate:delegate
  154. startSelector:startSelector stopSelector:stopSelector];
  155. [self.layer addAnimation:anim forKey:kFTAnimationFallIn];
  156. }
  157. - (void)fallOut:(NSTimeInterval)duration delegate:(id)delegate {
  158. [self fallOut:duration delegate:delegate startSelector:nil stopSelector:nil];
  159. }
  160. - (void)fallOut:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  161. CAAnimation *anim = [[FTAnimationManager sharedManager] fallOutAnimationFor:self duration:duration delegate:delegate
  162. startSelector:startSelector stopSelector:stopSelector];
  163. [self.layer addAnimation:anim forKey:kFTAnimationFallOut];
  164. }
  165. - (void)flyOut:(NSTimeInterval)duration delegate:(id)delegate {
  166. [self flyOut:duration delegate:delegate startSelector:nil stopSelector:nil];
  167. }
  168. - (void)flyOut:(NSTimeInterval)duration delegate:(id)delegate startSelector:(SEL)startSelector stopSelector:(SEL)stopSelector {
  169. CAAnimation *anim = [[FTAnimationManager sharedManager] flyOutAnimationFor:self duration:duration delegate:delegate
  170. startSelector:startSelector stopSelector:stopSelector];
  171. [self.layer addAnimation:anim forKey:kFTAnimationFlyOut];
  172. }
  173. @end