2009-08-24 108 views
2

我有了很多的內容(如信用視圖)一個UITextView,我想它(像針對Firefox的學分頁) 創建一個自動滾動視圖它會自動滾動的名字如何創建動畫信用頁面?

我曾嘗試以下,但它是不順利的,我還需要在用戶進入該視圖

CGPoint scrollPoint = textView.contentOffset; 

scrollPoint.y= scrollPoint.y+10; 

[textView setContentOffset:scrollPoint animated:YES]; 

任何指導,使其自動發生?

回答

1

由於UITextViewUIScrollView一個子類,你可以使用它的方法scrollRectToVisible:animated:動畫到任何你想要點滾動。

PageControl示例代碼演示了它的用法(儘管它是水平滾動的)。

0

到目前爲止,我已經做到了這一點,但它仍然是不順暢......

有什麼建議?

- (void)viewDidLoad { 

    [super viewDidLoad]; 

[self run]; 

} 

-(void)run{ 

    CGRect Frame1 = CGRectMake(5.0,5.0, 100.0,400.0); 
    CGPoint scrollPoint = textView.contentOffset; 

    scrollPoint.y= scrollPoint.y+100; 

    [textView setContentOffset:scrollPoint animated:YES]; 

    [textView scrollRectToVisible:Frame1 animated:YES]; 
    NSTimer *time; 
    time=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(run) userInfo:nil repeats:YES]; 

} 
0

既不scrollRectToVisible: animated:也不setContentOffset: animated:具有屬性來控制速度持續時間其中發生動畫,所以既會相當快速滾動到目的點。它們不適用於類似學分的應用,它應該緩慢滾動。

使用UIView animateWithDuration:然後在動畫塊中傳遞contentOffset可能是實現此目的的最佳方法。但是,如果文本的長度過長(即使在iOS 10.0 SDK中),也會有一個剪輯頂部的文本。對於此處討論的此錯誤有兩種可行的變通辦法:

UIView.animateWithDuration on UITextfield's contentoffset: It clips the text (Swift)