2015-07-11 32 views
0

我有一个让我感到困惑的情况。我有一个有2个完全分开的东西的类:一个动画UIImage和一个UILabel。他们有不同的网点,没有连接。线程问题更新标签使UIImageview不可见

当应用程序运行时,它这样做:

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.monsterMachine setHidden:NO]; //monsterMachine is UIImageView 
    [self.monsterMachine startAnimating]; 
}); 

但后来当我这样做:

[self.futText setText:@"blah"]; // is UILabel 

它会导致monsterMachine的UIImageView到不再动画。事情我已经找到:

右键我的setText后:@blah”我可以使用的NSLog观看,看到self.monsterMachine.isAnimated突然变从1到0,即从YES为NO

如果自我。 .futText是ALREADY说“blah”,那么我可以在它上面运行setText:@“blah”多次,并且什么都不会发生,只有当我将其更改为除blah之外的某个值时,UIImageView会停止动画并消失

如果我不使用main_queue显示和动画monsterMachine,它不会显示在所有的,所以我怎么诊断或解决这一问题?

+0

尝试添加[象征性的断点(https://developer.apple.com/library/ ios/recipes/xcode_help-breakpoint_navigator/articles/adding_a_symbolic_breakpoint.html)关于'stopAnimating',看看你是否能从调用树中找出导致它停止动画的原因。 – quantumkid

回答

1

这很奇怪,它对我来说很完美。你有没有调用[self.futText setText:@“blah”];在主队列中呢? 下面是为什么设置文本@“blah”不会停止动画的一个小答案: 像@“blah”这样的字符串存储在具有相同引用的堆栈中,只要它们具有相同的上下文。在这种情况下[self.futText的setText:@ “嗒嗒”]不会做任何事情,因为内部implementions像:

void setText:(NSString*) text { 
    if (_text == text) then return;//if reference is the same then do nothing 
    _text = text; 
    some rendering.. 
}