我正在尝试用属性化文本在UILabel中创建char动画
//set attributed string
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Yaba daba doo"];
[attributedString addAttribute:NSKernAttributeName value:@1 range:NSMakeRange(0, [attributedString length])];
//set animation
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
[self animateShowText:[attributedString string] characterDelay:0.1 withCurrentLabel:self.myLabel];
[self.myLabel setAttributedText:attributedString];
});我希望最后一条消息将设置带有属性的文本,但无法找到解决方案。在这里,我试图动画字符串的常规样式,并让标签显示属性字符串,但它没有工作。如何保存属性和动画文本?
发布于 2013-07-25 19:12:17
您应该只更新主线程上的视图。使用performSelectorOnMainThread:withObject:在块中这样做:
[self.myLabel performSelector: @selector(setAttributedText:) withObject: attributedString];如果动画显示文本调用更新视图的方法,那么您也应该这样做,或者选择使用dispatch_sync (此时我会说,不要使用GCD)。
https://stackoverflow.com/questions/17866679
复制相似问题