Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

iphone - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);  

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...