• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

在UIView开始动画后完成动作完成

IOS 来源:user3266053 4次浏览

我想在UIView动画完成时执行动作。在UIView开始动画后完成动作完成

if (flipStateHav1 == 1 && btnFrontHav1.tag == 1) { 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.8]; 

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainerHav1 cache:YES]; 
    [self.buttonContainerHav1 bringSubviewToFront:btnBackHav1]; 

    [UIView commitAnimations]; 

    //It is this code below I want to run after the animation is finish. 
    buttonContainerHav1.userInteractionEnabled = YES; 
    flipTurns = 0; 
    flipStateHav2 = 0; 
    par = 0; 
} 

我一直在使用

completion:^(BOOL finished){ 
    // your code 
}]; 

尝试,但没有得到它的工作,可能是我做错了什么。

更新代码 该按钮连接到两个操作。

- (IBAction) buttonPressedFlipHav1 { 

if (flipTurns == 0 || flipTurns == 1) { 

    flipTurns += 1; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.8]; 

     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainerHav1 cache:YES]; 
     [self.buttonContainerHav1 bringSubviewToFront:btnFrontHav1]; 
     buttonContainerHav1.userInteractionEnabled = NO; 
     flipStateHav1 = 1; 
     btnFrontHav1.tag = 1; 

     autoFlipCount += 1; 

     if (flipStateHav1 == 1 && flipStateHav2 == 1) { 
      par = 1; 
      parHav = 1; 
      btnFrontHav1.tag = 0; 
      btnFrontHav2.tag = 0; 

      flipTurns = 0; 
      autoFlipCount = 0; 

      if (parHav == 1 && parRiddare == 1 && parSkold == 1) { 

       autoFlipTimer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(autoFlipAll) userInfo:nil repeats:NO]; 

      } 
     } 

    } completion:^(BOOL finished) { 

    NSLog(@"autoFlipCount = %d",autoFlipCount); 
    NSLog(@"Flipturns = %d",flipTurns); 
    }]; 

    } 

} 

而且它也连接到这个动作。

- (IBAction) autoFlip { 
     autoFlipTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(callAfterFiveSecond) userInfo:nil repeats:NO]; 
} 

5秒后它跳到这个if语句。 更新

if (flipStateHav1 == 1 && btnFrontHav1.tag == 1) { 

    [UIView animateWithDuration:0.8 animations:^{ 

     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainerHav1 cache:YES]; 
     [self.buttonContainerHav1 bringSubviewToFront:btnBackHav1]; 

    } completion:^(BOOL finished) { 
     buttonContainerHav1.userInteractionEnabled = YES; 
     flipTurns = 0; 
     flipStateHav1 = 0; 
     par = 0; 
    }]; 

} 


===========解决方案如下:

此代码可以帮助你

[UIView animateWithDuration:0.4 animations:^{ 
    //animation code here` 
} completion:^(BOOL finished) { 
     //code after animation here 
}]; 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)