From c9ef6ce541acf2c0cd3f2bd26508226d96c814c5 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 1 Jun 2020 11:28:28 +0800 Subject: [PATCH] Added the convenient transition with duration APIs --- SDWebImage/Core/SDWebImageTransition.h | 30 +++++++++++++++++++++++++- SDWebImage/Core/SDWebImageTransition.m | 29 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/SDWebImage/Core/SDWebImageTransition.h b/SDWebImage/Core/SDWebImageTransition.h index f2f9a666..889372e4 100644 --- a/SDWebImage/Core/SDWebImageTransition.h +++ b/SDWebImage/Core/SDWebImageTransition.h @@ -83,7 +83,7 @@ typedef void (^SDWebImageTransitionCompletionBlock)(BOOL finished); */ @interface SDWebImageTransition (Conveniences) -/// Fade transition. +/// Fade-in transition. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *fadeTransition; /// Flip from left transition. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *flipFromLeftTransition; @@ -98,6 +98,34 @@ typedef void (^SDWebImageTransitionCompletionBlock)(BOOL finished); /// Curl down transition. @property (nonatomic, class, nonnull, readonly) SDWebImageTransition *curlDownTransition; +/// Fade-in transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)fadeTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(fade(duration:)); + +/// Flip from left transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)flipFromLeftTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(flipFromLeft(duration:)); + +/// Flip from right transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)flipFromRightTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(flipFromRight(duration:)); + +/// Flip from top transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)flipFromTopTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(flipFromTop(duration:)); + +/// Flip from bottom transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)flipFromBottomTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(flipFromBottom(duration:)); + +/// Curl up transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)curlUpTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(curlUp(duration:)); + +/// Curl down transition with duration. +/// @param duration transition duration, use ease-in-out ++ (nonnull instancetype)curlDownTransitionWithDuration:(NSTimeInterval)duration NS_SWIFT_NAME(curlDown(duration:)); + @end #endif diff --git a/SDWebImage/Core/SDWebImageTransition.m b/SDWebImage/Core/SDWebImageTransition.m index b7e379e1..93c83ecb 100644 --- a/SDWebImage/Core/SDWebImageTransition.m +++ b/SDWebImage/Core/SDWebImageTransition.m @@ -84,6 +84,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio @implementation SDWebImageTransition (Conveniences) + (SDWebImageTransition *)fadeTransition { + return [self fadeTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)fadeTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction; @@ -94,6 +98,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)flipFromLeftTransition { + return [self flipFromLeftTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)flipFromLeftTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionAllowUserInteraction; @@ -104,6 +112,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)flipFromRightTransition { + return [self flipFromRightTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)flipFromRightTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionFlipFromRight | UIViewAnimationOptionAllowUserInteraction; @@ -114,6 +126,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)flipFromTopTransition { + return [self flipFromTopTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)flipFromTopTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionFlipFromTop | UIViewAnimationOptionAllowUserInteraction; @@ -124,6 +140,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)flipFromBottomTransition { + return [self flipFromBottomTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)flipFromBottomTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionFlipFromBottom | UIViewAnimationOptionAllowUserInteraction; @@ -134,6 +154,10 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)curlUpTransition { + return [self curlUpTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)curlUpTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionAllowUserInteraction; @@ -144,12 +168,17 @@ CATransition * SDTransitionFromAnimationOptions(SDWebImageAnimationOptions optio } + (SDWebImageTransition *)curlDownTransition { + return [self curlDownTransitionWithDuration:0.5]; +} + ++ (SDWebImageTransition *)curlDownTransitionWithDuration:(NSTimeInterval)duration { SDWebImageTransition *transition = [SDWebImageTransition new]; #if SD_UIKIT transition.animationOptions = UIViewAnimationOptionTransitionCurlDown | UIViewAnimationOptionAllowUserInteraction; #else transition.animationOptions = SDWebImageAnimationOptionTransitionCurlDown; #endif + transition.duration = duration; return transition; }