Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Add support for customizing transition durations (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
randcode-generator authored May 30, 2017
1 parent 83bebb1 commit cf1e796
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/FadeExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ - (void)viewDidLoad {

@implementation FadeTransition

- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context {
return 0.3;
}

- (void)startWithContext:(id<MDMTransitionContext>)context {
[CATransaction begin];
[CATransaction setCompletionBlock:^{
Expand Down
11 changes: 11 additions & 0 deletions src/MDMTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ NS_SWIFT_NAME(Transition)

@end

/**
A transition with custom duration is able to override the default transition duration.
*/
NS_SWIFT_NAME(TransitionWithCustomDuration)
@protocol MDMTransitionWithCustomDuration
/**
The desired duration of this transition in seconds.
*/
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context;
@end

/**
A transition with presentation is able to customize the overall presentation of the transition,
including adding temporary views and changing the destination frame of the presented view
Expand Down
6 changes: 4 additions & 2 deletions src/private/MDMViewControllerTransitionContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ - (nonnull instancetype)initWithTransition:(nonnull id<MDMTransition>)transition
#pragma mark - UIViewControllerAnimatedTransitioning

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
// TODO(featherless): Expose a TransitionWithTiming protocol that allows the transition to
// customize this value.
if ([_transition respondsToSelector:@selector(transitionDurationWithContext:)]) {
id<MDMTransitionWithCustomDuration> withCustomDuration = (id<MDMTransitionWithCustomDuration>)_transition;
return [withCustomDuration transitionDurationWithContext:self];
}
return 0.35;
}

Expand Down

0 comments on commit cf1e796

Please sign in to comment.