开发者

animateWithDuration causing problems with UITextView

开发者 https://www.devze.com 2023-04-06 00:30 出处:网络
Earlier today I was trying to get some text in my app to autoscroll through the lyrics of the song that was currently playing and I got an answer to use the animateWithDuration method to get the scrol

Earlier today I was trying to get some text in my app to autoscroll through the lyrics of the song that was currently playing and I got an answer to use the animateWithDuration method to get the scroll to work properly. It worked fantastically until I noticed that when I use the following code, something covers up 80% of the textView in the same color as the textView background. When I swipe on the area covered (both in the simulator and on my test devices), the box (or whatever it is) disappears and all the text appears as normal. I know it's the method call of animateWithDuration, because I commented it out and the text isn't covered when I build and run with it not included in the project. Also I went into Interface Builder and changed the color of the textView to white (it was black along with the backgrounds of everything else in the view) to see if what was covering it ha开发者_如何学God a black background as well. When I changed it to white, the text was still covered, this time by a white box. Again it's only the very first time I unhide the textView and populate it with the lyrics for the song. After I swipe across the covered area, any song I play the obstruction doesn't appear. Just the initial time until it's swiped away. Here is the code I'm using...

// 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];

The following is what causes the text to get covered

    `// 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];`

And here's a photo of the before and after swiping the boxed area.

animateWithDuration causing problems with UITextView

Anyone have any idea what is covering the text or what I can do to get rid of it? Or another way I could autoscroll through the lyrics using another method besides animateWithDuration?

Here is the code I'm using to populate the textView with the lyrics.

- (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

EDIT: Well, I've solved the issue of the black box covering the text, though I don't understand it. While I was formatting the text file to flow better with the lyrics, my carriage returns as well as breaking lines up cause the text to get covered. I deleted the contents of the text file and re-pasted the original, resulting in none of the text being covered up. So now I guess my quest is to figure out how to format the text in the text file without having the text covered up. Any suggestions?


So apparently the text document was stored somewhere within the app, as I deleted all the text files in the resources folder and the text for the lyrics still appeared. I'm guessing it was using the size of the text files that were stored as anytime I made the text file smaller (by deleting lines from the double spacing), is where the problem came in. I formatted it how I wanted, and added a bunch of carriage returns at the end of my text document, and it works fine now.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号