是否有可能让UITextView自动滚动文本,并在Xcode中反复滚动?

时间:2015-02-03 03:14:49

标签: objective-c xcode6 uitextview

是否可以让UITextView自动滚动文本并反复滚动?就像,我有一个UITextView,文本只是滚动,滚动,当它到达结束时,一遍又一遍地重复,而无需用户滚动?

1 个答案:

答案 0 :(得分:1)

 - (void)viewDidLoad
        {    
          h=0;   // add the variable int h to your interface
            myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 
                                                           target:self 
                                                          selector:@selector(scrollPosition) 
                                                           userInfo:nil 
                                                           repeats:YES]; 
        }

- (void) scrollPosition {
                   h += 50; // add the variable int h to your interface
                //you must add the textview delegate to file's owner
                 [self.textview setContentOffset:CGPointMake(0, h) animated:YES];  

                   }

-(void)scrollViewDidScroll: (UIScrollView*)scrollView
                        {
                 float scrollViewHeight = scrollView.frame.size.height;
                 float scrollContentSizeHeight = scrollView.contentSize.height;
                 float scrollOffset = scrollView.contentOffset.y;
                    //  at the end of scrollview
                if (scrollOffset + scrollViewHeight >= scrollContentSizeHeight)
                            {
                //you must add the textview delegate to file's owner
                [self.textview setContentOffset:CGPointMake(0, 0) animated:YES]; 
                [myTimer invalidate];
                myTimer = nil;
                h=0;
                myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 
                                                               target:self 
                                                              selector:@selector(scrollPosition) 
                                                               userInfo:nil 
                                                               repeats:YES]; 
                            }
                        }