How to make scrollView fail on a crane

For example, on the iOS 7/8 lock screen, if you click, and do not drag it to the right, it will have a slight bounce effect. How can I detect a click gesture (and not confuse it with drag and drop) and recreate a similarly subtle “bounce” effect? Can anyone use a sample code (swift / obj-c)?

I think this is a great way to show the user that something needs to be dragged and not used, and does not require reading any small indicators.

+5
source share
3 answers

Add tap gesture to your view:

 UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; singleTap.cancelsTouchesInView = NO; [scrollView addGestureRecognizer:singleTap]; 

Can be done using UIView's animateWithDuration method in the handleTap: method handleTap:

 - (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; }]; } 
+2
source
 UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recognizeYourTap:)]; [self.yourView addGestureRecognizer:gestureRecognizer]; gestureRecognizer.cancelsTouchesInView = NO; - (void) recognizeYourTap:(UITapGestureRecognizer*)ges { //DO your Animation stuff what prince mentioned } 
+1
source

You can map the tap gesture using UITapGestureRecognize on the view. But you must implement some of the UIGestureRecognizerDelegate methods for working with gesture recognizers.

The bounce effect is made possible with the UIView animateWithDuration or with the CoreAnimation Framework

+1
source

Source: https://habr.com/ru/post/1209691/


All Articles