For example, on the iOS 7/8 lock screen, if you tap rather than drag it to the right, it will have a slight bounce effect. How can I detect the tap gesture (and not have it be confused with the dragging) and recreate a similarly subtle 'bounce' effect? Can anybody share a code example (swift/obj-c) ?
I think this is a great way to show the user that something should be dragged rather than tapped and it doesn't require reading any small indicators.
Add tap gesture
to your View like this:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];
Can be done using UIView's
animateWithDuration
method in handleTap:
method
- (void)handleTap:(UITapGestureRecognizer*)gesture
{
__block CGRect frame = scrollView.frame;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveLinear
animations:^{
frame.origin.x += 20.0f;
scrollView.frame = frame;
}
completion:^(BOOL finished){
scrollView.frame = frame;
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With