开发者

textview Automatic scroll in mintues

I have an app for iOS that display some files in a tableview which the filetype is "txt".I want to make a E-book app,it  can display the txt file in a textview,and count the words,input how many words /min user want to read ,the textv开发者_JAVA技巧iew begin to scroll and finish scroll in some minute Hope for you help,Thank you!


Use UITextView or a UIWebView, use a repeating NSTimer, calculate the ratio of how much of the minute is completed, and use it to set the contentOffset of the view.

Updated with more detail:

This is approximate and untested. It will scroll it in one minute. To create a timer,

NSTimer* timer = [scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateScroll) repeats:YES];
startingTime = NSDate.date.timeIntervalSinceNow; //store in object

Update the view. I think this will scroll the text off the screen.

-(void)updateScroll
{
    double minutesSinceStart = (NSDate.date.timeIntervalSinceNow - startingTime) / 60.0;
    myTextView.contentOffset = CGPointMake(minutesSinceStart * myTextView.contentSize.height, 0);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜