1

I have a view that changes if users scrolls it. I need something to read user's scroll data (direction, force etc.) like UITableView does it. if user touches screen and moves finger to the upwards view need to recieve scroll datas to call redraw method. How can I receive scroll data?

Venk
  • 5,949
  • 9
  • 41
  • 52
Oleg
  • 1,383
  • 4
  • 19
  • 35

1 Answers1

5

Yes you can get both.

To get the direction of scroll you need to implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView delegate.

int prevValue = 0;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int percentScrolled = abs((int)ceil((scrollView.contentOffset.y/scrollView.contentSize.height)*100));

    if(percentScrolled > prevValue)
        NSLog("Scrolling Down");
    else
        NSLog("Scrolling UP");

     prevValue = percentScrolled;
    return;
}

Now to get the force or power of scrolling. you actually need to set something called decelerateRate for your scrollView (or tableView). Refer here.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • It will work if I have a custom view that needs to be redrawed depending on where the users moves finger after he touches screen? – Oleg Nov 30 '11 at 11:22
  • I haven't got a UIScrollView object. I have UIView objects that rotate if user presses and moves finger on the screen (scrolling). So I need something to get scroll data from. – Oleg Nov 30 '11 at 11:35