jeudi 13 août 2015

UIView Animation with Simultaneous Counting Thread

I am trying to get a UIView to expand using an animation block, which works perfectly. However, I want a UILabel to start at 0 and every 0.01 seconds to add 1 till it gets to 100. I created a thread after the animation to accomplish this and it works but it causes the animation I setup to do nothing. I have tried many different things but have had no luck. What would be the best way to accomplish this?

My simplest attempt with the same result as all the others:

[UIView animateWithDuration:1 animations:^{
    _lView.frame = CGRectMake(_lView.frame.origin.x,_lView.frame.origin.y+_lView.frame.size.height,_lView.frame.size.width,-500);
}];

[[[NSThread alloc]initWithTarget:self selector:@selector(startcounting) object:nil]start];


-(void)startcounting{
for(int x=0; x<100; x++){
    [NSThread sleepForTimeInterval:0.01];
    ++_mcount;
    dispatch_async(dispatch_get_main_queue(), ^{
        _cLabel.text = [NSString stringWithFormat:@"%i",_mcount];
    });
  }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire