【问题标题】:Is it possible to have a UITextView scroll through text automatically, and repeatedly in Xcode?是否可以让 UITextView 自动滚动文本并在 Xcode 中重复滚动?
【发布时间】:2015-02-03 03:14:48
【问题描述】:

是否可以让 UITextView 自动重复滚动文本?就像,我有一个 UITextView,文本只是滚动,然后滚动,当它到达末尾时,它会一遍又一遍地重复,而无需用户滚动?

【问题讨论】:

标签: objective-c xcode6 uitextview


【解决方案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]; 
                            }
                        }

【讨论】:

  • “使用未声明的标识符 self”? @Chandu kumar.Alasyam
  • 嗨@TonyStark,您在其中添加“mytimer”。您必须在Viewdidload 或您的方法等方法中添加“mytimer”...我正在修改代码,请在它工作后检查很好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多