Skip to content

Commit

Permalink
Merge branch 'release/4.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Kim committed Nov 26, 2024
2 parents 8d46f87 + 8c3621d commit fbfa0ae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 32 deletions.
2 changes: 1 addition & 1 deletion AnimatedTransitionKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "AnimatedTransitionKit"
s.version = "4.0.2"
s.version = "4.0.3"
s.summary = "UIViewController Transitioning Library."
s.description = "This library helps you to apply and create Custom UIViewController Transitions."
s.homepage = "https://github.com/pisces/AnimatedTransitionKit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
#import "AbstractTransition.h"
#import "UIScrollView+Utils.h"

struct Percent {
CGFloat rawValue;
CGFloat processedValue;
};
typedef struct Percent Percent;

Percent PercentMake(CGFloat rawValue, CGFloat processedValue) {
Percent percent;
percent.rawValue = rawValue;
percent.processedValue = processedValue;
return percent;
}

const Percent PercentZero;

@interface PanningInteractiveTransition ()
@property (nonatomic, readonly) BOOL shouldInteractiveTransition;
@property (nonatomic, readonly) UIPanGestureRecognizer *panGestureRecognizer;
Expand Down Expand Up @@ -185,38 +200,10 @@ - (void)panned:(UIPanGestureRecognizer *)panGestureRecognizer {
return;
}

const CGSize screenSize = UIScreen.mainScreen.bounds.size;
const BOOL isStartPanningDirectionVertical = PanningDirectionIsVertical(self.startPanningDirection);
CGFloat translationValue;
CGFloat targetSize;
CGFloat velocityValue;
switch (self.direction) {
case InteractiveTransitionDirectionVertical:
translationValue = self.translation.y;
targetSize = screenSize.height;
velocityValue = self.velocity.y;
break;
case InteractiveTransitionDirectionHorizontal:
translationValue = self.translation.x;
targetSize = screenSize.width;
velocityValue = self.velocity.x;
break;
case InteractiveTransitionDirectionAll:
translationValue = isStartPanningDirectionVertical ? self.translation.y : self.translation.x;
targetSize = isStartPanningDirectionVertical ? screenSize.height : screenSize.width;
velocityValue = isStartPanningDirectionVertical ? self.velocity.y : self.velocity.x;
break;
}

const BOOL isAppearing = [self.transition isAppearing:self];
const CGFloat fixedTranslationValue = translationValue - self.translationOffset;
const CGFloat interactionDistance = targetSize * (isAppearing ? -1 : 1);
const CGFloat percent = fmin(fmax(-1, fixedTranslationValue / interactionDistance), 1);
const CGFloat multiply = MAX(1, ABS(velocityValue / 300));
const CGFloat percentForComparison = ABS(percent * multiply);
Percent percent = [self percentWhenPanningChanged];
_shouldComplete = percent.processedValue > self.percentForCompletion && [self.transition shouldCompleteInteractor:self];

_shouldComplete = percentForComparison > self.percentForCompletion && [self.transition shouldCompleteInteractor:self];
[self updateInteractiveTransition:percent];
[self updateInteractiveTransition:percent.rawValue];
break;
}
case UIGestureRecognizerStateCancelled:
Expand All @@ -240,4 +227,47 @@ - (void)panned:(UIPanGestureRecognizer *)panGestureRecognizer {
}
}

- (Percent)percentWhenPanningChanged {
const CGSize screenSize = UIScreen.mainScreen.bounds.size;
switch (self.direction) {
case InteractiveTransitionDirectionVertical:
return [self percentWithTranslation:self.translation.y
size:screenSize.height
velocity:self.velocity.y];
case InteractiveTransitionDirectionHorizontal:
return [self percentWithTranslation:self.translation.x
size:screenSize.width
velocity:self.velocity.x];
case InteractiveTransitionDirectionAll:
return [self percentForDirectionAllWithScreenSize:screenSize];
}
}

- (Percent)percentForDirectionAllWithScreenSize:(CGSize)screenSize {
Percent verticalPercent = [self percentWithTranslation:self.translation.y
size:screenSize.height
velocity:self.velocity.y];
Percent horizontalPercent = [self percentWithTranslation:self.translation.x
size:screenSize.width
velocity:self.velocity.x];
const BOOL isStartPanningDirectionVertical = PanningDirectionIsVertical(self.startPanningDirection);

if (isStartPanningDirectionVertical) {
return verticalPercent.processedValue > horizontalPercent.processedValue ? verticalPercent : PercentZero;
}
return horizontalPercent.processedValue > verticalPercent.processedValue ? horizontalPercent : PercentZero;
}

- (Percent)percentWithTranslation:(CGFloat)translation
size:(CGFloat)size
velocity:(CGFloat)velocity {
const BOOL isAppearing = [self.transition isAppearing:self];
const CGFloat bounds = translation - self.translationOffset;
const CGFloat interactionDistance = size * (isAppearing ? -1 : 1);
const CGFloat rawValue = fmin(fmax(-1, bounds / interactionDistance), 1);
const CGFloat multiply = MAX(1, ABS(velocity / 300));
const CGFloat processedValue = ABS(rawValue * multiply);
return PercentMake(rawValue, processedValue);
}

@end

0 comments on commit fbfa0ae

Please sign in to comment.