Skip to content

Commit 7c373b0

Browse files
committed
Added more appropriate iOS 17 tap APIs
1 parent 831bd3c commit 7c373b0

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

TORoundedButton/TORoundedButton.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
154154

155155
// Create action events for all possible interactions with this control
156156
[self addTarget:self action:@selector(_didTouchDownInside) forControlEvents:UIControlEventTouchDown|UIControlEventTouchDownRepeat];
157-
[self addTarget:self action:@selector(_didTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
157+
[self addTarget:self action:@selector(_didTouchUpInside:event:) forControlEvents:UIControlEventTouchUpInside];
158158
[self addTarget:self action:@selector(_didDragOutside) forControlEvents:UIControlEventTouchDragExit|UIControlEventTouchCancel];
159159
[self addTarget:self action:@selector(_didDragInside) forControlEvents:UIControlEventTouchDragEnter];
160160
}
@@ -339,11 +339,16 @@ - (void)_didTouchDownInside {
339339
[self _setButtonScaledTappedAnimated:YES];
340340
}
341341

342-
- (void)_didTouchUpInside {
342+
- (void)_didTouchUpInside:(id)sender event:(UIEvent *)event {
343343
_isTapped = NO;
344344

345-
// Play the impact.
346-
[_impactGenerator impactOccurred];
345+
// Play the impact to lock in that the user committed to this action.
346+
if (@available(iOS 17.5, *)) {
347+
const CGPoint touchPoint = [event.allTouches.anyObject locationInView:self];
348+
[_impactGenerator impactOccurredAtLocation:touchPoint];
349+
} else {
350+
[_impactGenerator impactOccurred];
351+
}
347352

348353
// The user lifted their finger up from inside the button bounds
349354
[self _setLabelAlphaTappedAnimated:YES];

0 commit comments

Comments
 (0)