2011-09-08 12 views
2
I've got my UITextView set up for scrolling like this, 

-(void)startAutoScroll 
{ 
    NSLog(@"AutoScroll Started"); 
    if (scrollingTimer == nil) { 
     scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:(60.0/1000.0) 
                  target:self 
                 selector:@selector(autoscrollTimerFired:) 
                 userInfo:nil 
                 repeats:YES]; 
    } 

} 

- (void) autoscrollTimerFired:(NSTimer *)timer 
{ 
    scrollPoint = self.completeText.contentOffset; 
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + velocityFactor); 
    [self.completeText setContentOffset:scrollPoint animated:NO]; 
} 

如何啓用平滑滾動?謝謝如何在UITextView中啓用平滑滾動?

+0

velocityFactor應該是小和[self.completeText setContentOffset:scrollPoint動畫:是]; //應該是 –

+0

當我設置爲YES的事情變得更糟 –

+0

動畫應該是NO。隨着您所調用的更新速率(大約15 FPS),動畫在平滑度上將沒有什麼區別,並可能導致連續快速調用某些意外行爲。 – Dancreek

回答

1

您可以使用動畫NO來逐個像素地滾動像素,因爲它在完成滾動後不會像動畫YES屬性那樣停止。你唯一需要設置的是velocityFactor,因爲你的NSTimer應該被調用,而不是滾動應該移動。在用contentSize完成滾動後,使計時器無效,滾動應該停止。

- (void) autoscrollTimerFired:(NSTimer *)timer { 
    [self.completeText setContentOffset:CGPointMake(0, self.completeText.contentOffset.y + 1.0) animated:NO]; 
    if (self.completeText.contentOffset.y != self.completeText.contentSize.height - self.completeText.frame.size.height) { 
     scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:velocityFactor target:self selector:@selector(autoscrollTimerFired:) userInfo:nil repeats:NO]; 
    } else { 
     [scrollingTimer invalidate]; 
    } 
} 
+0

謝謝)真的幫助)好主意,順利地滾動UITextView的最佳方式 –