今天早些時候,我試圖在我的應用程序中獲取一些文本來自動滾動當前正在播放的歌曲的歌詞,並且我得到了使用animateWithDuration方法使滾動正常工作的答案。直到我注意到當我使用下面的代碼時,它的工作非常精彩,東西覆蓋了與textView背景相同顏色的80%的textView。當我在所覆蓋的區域(包括模擬器和我的測試設備上)滑動時,框(或其它)會消失,並且所有文本都顯示爲正常。我知道這是animateWithDuration的方法調用,因爲我將它評論出來,並且在構建和運行未包含在項目中的文本時未覆蓋文本。此外,我進入Interface Builder並將textView的顏色更改爲白色(與視圖中其他所有內容的背景一起顯示爲黑色),以查看覆蓋它的內容是否也具有黑色背景。當我將它改爲白色時,文本仍然被覆蓋,這次是一個白色框。同樣,這只是我第一次取消隱藏textView,併爲歌曲填充歌詞。在我滑過被覆蓋的區域之後,我播放阻塞的任何歌曲都不會出現。只是最初的時間,直到它被刷掉。下面是我使用的代碼...animateWithDuration導致UITextView問題
// set the textView to start at the top of the document
[textView setContentOffset:CGPointZero];
CGPoint scrollPoint = textView.contentOffset;
// set the scroll point to the length of the text view, so it knows how far down to go
scrollPoint.y= [textView.text length];
下面是什麼原因造成的文本得到覆蓋
`// animate down to that point at the rate of the length of the song minus 20 seconds (so the lyrics can catch up to the song)
[UIView animateWithDuration:(self.myMusicPlayer.duration - 20)
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^(void) {self.textView.contentOffset = scrollPoint;}
completion:nil];`
而這裏的前後滑動方框區域後的照片。
任何人有任何想法是怎麼覆蓋文本或我能做些什麼來擺脫它?或者,除了animateWithDuration之外,還可以使用另一種方法自動滾動歌詞?
這裏是我用來填充textView與歌詞的代碼。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { // determine which row was clicked
NSUInteger row = [indexPath row];
// get the song name from the array at the position clicked
NSString *rowString = [songNames objectAtIndex:row];
// load the lyrics for the song played into the textView
// load the text file for the song selected
NSString *lyrics = [[NSBundle mainBundle] pathForResource:rowString ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:lyrics];
// set the textView to load the lyric sheet for the song selected
self.textView.text = fileContents; // more after this, but this is all that I'm doing with the textView
編輯:嗯,我已經解決了黑盒子覆蓋文本的問題,雖然我不明白。當我格式化文本文件以更好地播放歌詞時,我的回車以及斷行將導致文本被覆蓋。我刪除了文本文件的內容並重新粘貼了原文,導致沒有任何文字被遮蓋。所以現在我想我的任務是弄清楚如何格式化文本文件中的文本,而不會覆蓋文本。有什麼建議麼?
我不確定這是否會解決您的問題,但嘗試設置文本視圖的顏色以清除。 'self.textView.backgroundColor = [UIColor clearColor];' –
明智的建議,但不幸的是它沒有奏效。 –