ios - 我的animatewithduration,完成 block 只执行一次

标签 ios objective-c

我使用以下代码块向下滑动一个 UIView,并在完成后旋转另一个 UIView。 动画的第二部分,完成 block 只执行一次,这意味着第一个动画没有完成,否则它会到达完成 block 。 在 iphone 模拟器上它看起来好像第一个动画确实完成了...... 谁能帮我解决这个问题? 我的 NSLog 说:

finished 1st

started 2nd

finished 1st

finished 1st

finished 1st
.
.
.

- (IBAction) move 
{ 
[UIView animateWithDuration:0.7 animations:^{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.7];
    [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatAutoreverses:NO];

    CGPoint pos = movingtTable.center;
    float moveDistance = 220.0;
    if(!isViewVisible){
        //expose the view
        pos.y = pos.y+moveDistance;
        //disable selection for xy table
        xTable.userInteractionEnabled = NO;
        yTable.userInteractionEnabled = NO;
        //angle = M_PI;
    }
    else
    {
        pos.y = pos.y-moveDistance;
        xTable.userInteractionEnabled = YES;
        yTable.userInteractionEnabled = YES;
        //angle = -M_PI;
    }
    isViewVisible = !isViewVisible;
    movingtTable.center = pos;      
    NSLog(@"finished 1st");


}completion:^(BOOL finished){
    NSLog(@"started 2nd");
        [UIView animateWithDuration:0.4 animations:^{
            //[UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.4];
            //[UIView setAnimationRepeatCount:1];
            //[UIView setAnimationRepeatAutoreverses:NO];
            arrows.transform = CGAffineTransformMakeRotation(angle); 
         }completion:^(BOOL finished){
             angle = -angle;
         }];
}];

最佳答案

为什么要在 animateWithDuration block 代码中尝试初始化另一个 UIView 动画?将您的代码更新为以下内容,并确保您不会一次对单个 View 执行多个动画。

- (IBAction) move 
{ 
[UIView animateWithDuration:0.7 animations:^{
    CGPoint pos = movingtTable.center;
    float moveDistance = 220.0;
    if(!isViewVisible){
        //expose the view
        pos.y = pos.y+moveDistance;
        //disable selection for xy table
        xTable.userInteractionEnabled = NO;
        yTable.userInteractionEnabled = NO;
        //angle = M_PI;
    }
    else
    {
        pos.y = pos.y-moveDistance;
        xTable.userInteractionEnabled = YES;
        yTable.userInteractionEnabled = YES;
        //angle = -M_PI;
    }
    isViewVisible = !isViewVisible;
    movingtTable.center = pos;      
    NSLog(@"finished 1st");
}
completion:^(BOOL finished){
    NSLog(@"started 2nd");
        [UIView animateWithDuration:0.4 animations:^{
            arrows.transform = CGAffineTransformMakeRotation(angle); 
         }completion:^(BOOL finished){
             angle = -angle;
         }];
}];

顺便说一句:如果你问我的话, block 代码需要一些认真的重构:)

关于ios - 我的animatewithduration,完成 block 只执行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9949719/

相关文章:

ios - 计算 ios 、 Objective C 和 Swift 中任何数字的平方根的最佳方法

ios - 如何使用 Xamarin for Visual Studio 2013 为我的 iOS 应用构建 IPA 文件

ios - localizable.string 不存在时如何设置默认语言?

ios - NSDate 中的时间/日期显示就像 iOS 中的消息和邮件应用程序一样

iphone - 应用内购买免费订阅提示用户分享信息

ios - 为什么不分配这些 NSString 实例变量?

ios - UITableViewController 不会用 NSFetchedResultsControllerDelegate + UISearchBarDelegate 更新

ios - 自定义键盘返回标题设置 IOS8

ios - 如何解决不明确的布局?

ios - Settings.app中的表是如何实现的?