【问题标题】:UIImage view resets after animation is called调用动画后 UIImage 视图重置
【发布时间】:2013-02-11 05:52:27
【问题描述】:

我是核心动画的新手。每次我调用动画时,我的图像都会从它的位置移动到屏幕的左上角,移动,然后回到原始位置。如何使图像向左移动 50 个单位,停止,然后在再次按下按钮时重复。 代码:

-(IBAction)preform:(id)sender{

CGPoint point = CGPointMake(50, 50);

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position"];
anim.fromValue  = [NSValue valueWithCGPoint:point];
anim.toValue    = [NSValue valueWithCGPoint:CGPointMake(point.x + 50, point.y)];
anim.duration   = 1.5f;
anim.repeatCount =1;
anim.removedOnCompletion = YES;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[imView.layer  addAnimation:anim forKey:@"position"];

}

【问题讨论】:

    标签: ios cocoa-touch core-animation caanimation


    【解决方案1】:

    对于您的情况,您可以跳过繁重的 CA 机器并使用块动画

    // Your image is at starting position
    [UIView animateWithDuration:1.5 animations:^{
            CGRect newFrame = CGRectOffset(imView.frame, 50, 0);
            imView.frame = newFrame;
        }];
    

    但是,如果您想知道如何正确处理这种“回弹”,请查看this url

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多