Skip to content

Commit 42f33ab

Browse files
committed
Separated out the tap down and up durations
1 parent 8080944 commit 42f33ab

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

TORoundedButton/TORoundedButton.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
125125
/// When tapped, the scale by which the button shrinks during the animation (Default is 0.97f).
126126
@property (nonatomic, assign) IBInspectable CGFloat tappedButtonScale;
127127

128-
/// The duration of the tapping cross-fade animation (Default is 0.4f).
129-
@property (nonatomic, assign) CGFloat tapAnimationDuration;
128+
/// The duration of the tap-down animation (Default is 0.1f).
129+
@property (nonatomic, assign) CGFloat tapDownAnimationDuration;
130+
131+
/// The duration of the tap-up animation (Default is 0.4f).
132+
@property (nonatomic, assign) CGFloat tapUpAnimationDuration;
130133

131134
/// A callback handler triggered each time the button is tapped.
132135
@property (nonatomic, copy) void (^tappedHandler)(void);

TORoundedButton/TORoundedButton.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ - (instancetype)initWithText:(NSString *)text {
116116
- (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
117117
// Default properties (Make sure they're not overriding IB)
118118
_tappedTextAlpha = (_tappedTextAlpha > FLT_EPSILON) ?: 1.0f;
119-
_tapAnimationDuration = (_tapAnimationDuration > FLT_EPSILON) ?: 0.4f;
119+
_tapDownAnimationDuration = (_tapDownAnimationDuration > FLT_EPSILON) ?: 0.1f;
120+
_tapUpAnimationDuration = (_tapUpAnimationDuration > FLT_EPSILON) ?: 0.4f;
120121
_tappedButtonScale = (_tappedButtonScale > FLT_EPSILON) ?: 0.97f;
121122
_tappedTintColorBrightnessOffset = !TORoundedButtonFloatIsZero(_tappedTintColorBrightnessOffset) ?: 0.25f;
122123
_contentInset = (UIEdgeInsets){15.0, 15.0, 15.0, 15.0};
@@ -385,7 +386,7 @@ - (void)_didDragInside {
385386

386387
- (void)_performTapAnimation:(void (^)(void))animations
387388
completion:(void (^_Nullable)(BOOL finished))completion TOROUNDEDBUTTON_OBJC_DIRECT {
388-
[UIView animateWithDuration:_tapAnimationDuration
389+
[UIView animateWithDuration:_isTapped ? _tapDownAnimationDuration : _tapUpAnimationDuration
389390
delay:0.0f
390391
usingSpringWithDamping:1.0f
391392
initialSpringVelocity:0.5f

0 commit comments

Comments
 (0)