先说一下我想做什么:
我想要在一个类A中调用另一个viewcontroler显示动画,在动画执行完之后类A继续执行我当前的做法:
在类A中新建线程,线程中调用动画函数,并在线程前加锁,在动画执行完之后调用animationDidStop解锁。
遇到的问题:
执行完之后不会调用animationDidStop,但是如果我使用定时则可以调用animationDidStop以下是我大致的代码://类A:
                [_lock lock];
                [NSThread detachNewThreadSelector:@selector(moveChess) toTarget:self withObject:nil];
                [_lock lock];
                NSLog(@"_lock locked");
                [_lock unlock];
/*使用定时则可以调用animationDidStop
  [NSThread detachNewThreadSelector:@selector(moveChess) toTarget:self withObject:nil];
[NSThread sleepForTimeInterval:0.5f];
*/
//moveChess
               -(void)moveChess{
                          NSLog(@"moveChess... ...");
                           [self->_delegate moveChess:_preTag toTag:_tag];
                 }//viewcontroler
//委托方法:移动棋子动画
-(void)moveChess:(int64_t)fromTag toTag:(int64_t)toTag{
    UIButton * btn1=(UIButton*)[self.view viewWithTag:fromTag];
    UIButton * btn2=(UIButton*)[self.view viewWithTag:toTag];
    CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"position"];
    anima.fromValue = [NSValue valueWithCGPoint:btn1.center];
    anima.toValue = [NSValue valueWithCGPoint:btn2.center];
    anima.duration = 0.5f;
    [_chessBtn[fromTag%100].layer addAnimation:anima forKey:@"moveChessAnimation"];
}
//
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    NSLog(@"fdsafdsa1");
    [self->_game->_lock unlock];
    NSLog(@"unlock");
}
//