Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto scroll UIScrollView using timer?

I have a UIScrollView to show images. I need a timer to show the images one after another, after every 5 seconds. How to initiate UIScrollView event to move to the next image after 5 seconds using the timer?

like image 527
varmab Avatar asked Sep 12 '10 09:09

varmab


People also ask

How do I set up automatic scrolling?

To use you just need to press CTRL+ Left click of your mouse and drag the mouse a bit in the direction you want to scroll the page. For example, if you want to scroll up to the page automatically, click CTRL+ left click and slightly move your mouse upwards, the tool will start scrolling up the page.

How do I make Div scroll automatically?

Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

What is auto scroll speed?

The autoscroll timer runs at 100ms (assuming a default double-click speed of 500ms), and if the mouse move message is generated after, say, 25ms, then the autoscroll should move only a quarter of its usual distance, rather than the full distance.

What auto scroll means?

To scroll by dragging the mouse pointer beyond the edge of the current window or screen. It is used to move around a virtual screen as well as to highlight text blocks and images that are larger than the current window.


2 Answers

Add the variable int h to your interface, and yourScrollView as a property. Then:

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

- (void) onTimer {

    // Updates the variable h, adding 100 (put your own value here!)
    h += 100; 

    //This makes the scrollView scroll to the desired position  
    yourScrollView.contentOffset = CGPointMake(0, h);  

}
like image 145
Abramodj Avatar answered Oct 26 '22 19:10

Abramodj


modifying the above code

 [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(onTimer)   userInfo:nil repeats:YES];

-(void) onTimer {
  // NSLog(@"content offset %f",scrollVw.contentOffset.y);
  if (scrollVw.contentOffset.y<MAX_ALLOWED_OFFSET) {
   //scroll to desire position
    scrollVw.contentOffset = CGPointMake(0, scrollVw.contentOffset.y+1);
  }


  }
like image 23
iSankha007 Avatar answered Oct 26 '22 19:10

iSankha007