是否可以让 UITextView 自动滚动文本,并在 Xcode 中重复?
Is it possible to have a UITextView scroll through text automatically, and repeatedly in Xcode?
是否可以让 UITextView 自动重复滚动文本?比如,我有一个 UITextView,文本只是滚动,然后滚动,当它到达末尾时,一遍又一遍地重复自己,而不需要用户滚动?
- (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];
}
}
是否可以让 UITextView 自动重复滚动文本?比如,我有一个 UITextView,文本只是滚动,然后滚动,当它到达末尾时,一遍又一遍地重复自己,而不需要用户滚动?
- (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];
}
}