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

Commit cf1e796

Browse files
Add support for customizing transition durations (#11)
#2
1 parent 83bebb1 commit cf1e796

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

examples/FadeExample.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ - (void)viewDidLoad {
6060

6161
@implementation FadeTransition
6262

63+
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context {
64+
return 0.3;
65+
}
66+
6367
- (void)startWithContext:(id<MDMTransitionContext>)context {
6468
[CATransaction begin];
6569
[CATransaction setCompletionBlock:^{

src/MDMTransition.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ NS_SWIFT_NAME(Transition)
3636

3737
@end
3838

39+
/**
40+
A transition with custom duration is able to override the default transition duration.
41+
*/
42+
NS_SWIFT_NAME(TransitionWithCustomDuration)
43+
@protocol MDMTransitionWithCustomDuration
44+
/**
45+
The desired duration of this transition in seconds.
46+
*/
47+
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context;
48+
@end
49+
3950
/**
4051
A transition with presentation is able to customize the overall presentation of the transition,
4152
including adding temporary views and changing the destination frame of the presented view

src/private/MDMViewControllerTransitionContext.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ - (nonnull instancetype)initWithTransition:(nonnull id<MDMTransition>)transition
5050
#pragma mark - UIViewControllerAnimatedTransitioning
5151

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

0 commit comments

Comments
 (0)