Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Final answer, Using UIView animation, I got what i want.</p> <pre><code>- (IBAction)buttonTouchedDown:(id)sender withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; self.oldPoint = [touch locationInView:self.view]; self.velocity = 0; isButtonTouchedDown = YES; } - (IBAction)buttonTouchedMove:(id)sender withEvent:(UIEvent *)event { CGPoint offset = self.scrollView1.contentOffset; UITouch *touch = [[event allTouches] anyObject]; self.newPoint = [touch locationInView:self.view]; int diffX = self.newPoint.x - self.oldPoint.x; velocity = diffX; offset.x = offset.x - diffX; [self.scrollView1 setContentOffset:offset animated:NO]; self.oldPoint = self.newPoint; } </code></pre> <p>There is a trick..I calculated velocity by differentiating moved distance in TouchedMove function. In Button TouchUp event handler, I controlled Scrollview with velocity value and CurveEaseout animation to scroll more. By offering very short duration of animation and repeating it if there is no event(button touched down). It becomes very similar with scrollview's animation.</p> <pre><code>- (IBAction)buttonTouchedUp:(id)sender withEvent:(UIEvent *)event { CGPoint offset = self.scrollView1.contentOffset; amountX = (self.velocity)*(abs(self.velocity)); dX = amountX; isButtonTouchedDown = NO; if (offset.x - amountX &lt; 0) { offset.x = 0; [scrollView1 setContentOffset:offset animated:YES]; } else if (abs(dX) &lt; 70) { // 70: content item size offset.x = roundf(offset.x/70)*70; [scrollView1 setContentOffset:offset animated:YES]; } else { [self endScrollAnimation]; } - (void)startAnimation:(float)x moveAmount:(float)moveAmount { CGPoint offset = self.scrollView1.contentOffset; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:duration]; offset.x = x &lt; 0 ? offset.x + moveAmount : offset.x -moveAmount; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(endScrollAnimation)]; [scrollView1 setContentOffset:offset animated:NO]; [UIView commitAnimations]; } - (void)endScrollAnimation { CGPoint offset = self.scrollView1.contentOffset; float slowMoveAmount = abs(amountX) * 0.05; float fastMoveAmount = abs(amountX) * 0.1; if (isButtonTouchedDown) { return; } else if (abs(dX) &gt; abs(amountX)*0.35 &amp;&amp; offset.x &gt; 0) { [self startAnimation:dX moveAmount:fastMoveAmount]; dX = dX &lt; 0 ? dX + fastMoveAmount : dX -fastMoveAmount; } else if (abs(dX) &gt; slowMoveAmount &amp;&amp; offset.x &gt; 0) { [self startAnimation:dX moveAmount:slowMoveAmount]; dX = dX &lt; 0 ? dX + slowMoveAmount : dX - slowMoveAmount; } else { offset.x = roundf(offset.x/70)*70; [scrollView1 setContentOffset:offset animated:YES]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload