代码之家  ›  专栏  ›  技术社区  ›  Oh Danny Boy

使用CGAffine在弧上移动UIImageView

  •  0
  • Oh Danny Boy  · 技术社区  · 14 年前

    CGAffineTransformMakeRotation CGAffineTransformMakeTranslation 翻译图像。我也明白 CGAffineTransformConcat 可以合并两个变换。然而,我似乎无法想出一种方法来移动一个弧形图像使用这两个。我知道这更像是一个数学问题,但有人能给我提供参考吗?

    编辑:

     [bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:]
    

    参考文献: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/clm/UIBezierPath/bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise

    2 回复  |  直到 14 年前
        1
  •  2
  •   Jason Harwig    14 年前

    使用 CAKeyframeAnimation 设置路径而不是离散值。

    CAKeyframeAnimation *a = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    CGRect circleRect = CGRectMake(0,0,50,50);
    a.duration = 2.0;
    a.rotationMode = kCAAnimationRotateAuto;
    a.path = [UIBezierPath bezierPathWithOvalInRect:circleRect].CGPath;
    [imageView.layer addAnimation:a forKey:@"moveCircle"];
    
        2
  •  1
  •   William Jockusch    14 年前

    围绕与弧相对应的圆心旋转。

    这将涉及三个步骤:

    1) 平移以使弧的中心移动到原点。
    2) 旋转适当的角度。