我正在尝试为 NSString 设置动画并使其逐字符显示。虽然我在 NSLog 中看到该功能确实有效,但在动画期间文本不会出现在 UITextView 上,只有在动画结束时才会出现。
我的代码:
- (void)viewDidAppear:(BOOL)animated
{
[self performSelectorOnMainThread:@selector(startAnimation) withObject:nil waitUntilDone:NO];
}
#pragma mark - General Methods
- (void)animateCharacterByCharacter_text:(NSString *)text characterDelay:(NSTimeInterval)characterDelay
{
[self.textAbout setText:@""];
for (int i=0; i < text.length; i++)
{
NSString *textToSet = [NSString stringWithFormat:@"%@%c", self.textAbout.text, [text characterAtIndex:i]];
self.textAbout.text = textToSet;
NSLog(@"%@", textToSet);
[NSThread sleepForTimeInterval:characterDelay];
}
}
- (void)startAnimation
{
NSString *stringAbout = @"sfhasdf\nhajsbdh";
[self animateCharacterByCharacter_text:stringAbout characterDelay:0.5];
}
我也一直在尝试使用“dispatch_async”,得到了相同的结果。我做错了什么?