【问题标题】:CABasicAnimation not working all the timeCABasicAnimation 一直不工作
【发布时间】:2015-08-13 04:50:19
【问题描述】:

我有下面的代码应该给出视图“抖动”的效果,然后通过从屏幕上滑出来消除它。

有时它呈现完美,但大多数时候摇动动画不会显示,视图只会向上滑动。我无法弄清楚问题可能是什么:

CABasicAnimation *animation =
        [CABasicAnimation animationWithKeyPath:@"position"];
        [animation setDuration:0.05];
        [animation setRepeatCount:8];
        [animation setAutoreverses:YES];
        [animation setFromValue:[NSValue valueWithCGPoint:
                                 CGPointMake([[self editView] center].x - 20.0f, [[self editView] center].y)]];
        [animation setToValue:[NSValue valueWithCGPoint:
                               CGPointMake([[self editView] center].x + 20.0f, [[self editView] center].y)]];
        [[[self editView] layer] addAnimation:animation forKey:@"position"];
        
        [CATransaction begin]; {
            [CATransaction setCompletionBlock:^{
                
                
                [UIView animateWithDuration:0.4f delay:0.7 options:UIViewAnimationOptionTransitionNone animations:^{
                    
                    _editView.center = CGPointMake(self.navigationController.view.bounds.size.width / 2, 0 - 380);
                    [_textView resignFirstResponder];
                    
                    [_tint setAlpha:0];
                    
                    
                } completion:^(BOOL finished) {
                    
                    [_editView removeFromSuperview];
                    [_tint removeFromSuperview];
                }];
                
            }];
            
} [CATransaction commit];

【问题讨论】:

    标签: ios objective-c swift cabasicanimation catransaction


    【解决方案1】:

    你需要做的唯一改变就是更换:

    [[[self editView] layer] addAnimation:animation forKey:@"position"];
    

    [CATransaction commit];的正上方。

    因此,它变成:

    [CATransaction begin];
    {
        [CATransaction setCompletionBlock:^
        {
            [UIView animateWithDuration:0.4f delay:0.7f options:UIViewAnimationOptionTransitionNone animations:^
            {
                _editView.center = CGPointMake(self.navigationController.view.bounds.size.width / 2.0f, -380.0f);
               [_textView resignFirstResponder];
               [_tint setAlpha:0];
            }
            completion:^(BOOL finished)
            {
                [_editView removeFromSuperview];
                [_tint removeFromSuperview];
            }];
        }];
    }
    [[[self editView] layer] addAnimation:animation forKey:@"position"];
    [CATransaction commit];
    

    然后,震动部分将首先发生,然后它开始按照您的意愿向上动画。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多