iPhone 动画 - 将视图移动一圈

发布于 2024-10-31 11:11:05 字数 71 浏览 3 评论 0原文

有没有办法在不使用视图动画旋转视图的情况下围绕中心点移动视图?

   A

A  C  A

   A

Is there a way to move a view around a center point without rotating it using the view animations?

   A

A  C  A

   A

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2024-11-07 11:11:05
    #import <QuartzCore/QuartzCore.h>
    #define degreesToRadians(deg) (deg / 180.0 * M_PI)

Manualy :

-(CGPoint)setPointToAngle:(int)angle center:(CGPoint)centerPoint radius:(double)radius
 {
    return CGPointMake(radius*cos(degreesToRadians(angle)) + centerPoint.x, radius*sin(degreesToRadians(angle)) + centerPoint.y);
 }

带有类似这样的动画:

    int angle = 0; // start angle position 0-360 deg
    CGPoint center = self.view.center;
    CGPoint start = [self setPointToAngle:angle center:center radius:radius]; //point for start moving
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, start.x, start.y);

    for(int a =0;a<4;a++) //set path points for 90, 180, 270,360 deg form begining angle
    {
        angle+=45;
        expPoint = [self setPointToAngle:angle center:center radius:expRadius];
        angle+=45;
        start = [self setPointToAngle:angle center:center radius:radius];
        CGPathAddQuadCurveToPoint(path, NULL,expPoint.x, expPoint.y, start.x, start.y);
    }

    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.removedOnCompletion = NO;
    pathAnimation.path = path;
    [pathAnimation setCalculationMode:kCAAnimationCubic];
    [pathAnimation setFillMode:kCAFillModeForwards];
    pathAnimation.duration = 14.0; 

    [MY_VIEW.layer addAnimation:pathAnimation forKey:nil];

也看看

CGPathAddQuadCurveToPoint, 
CGPathAddCurveToPoint, 
CGPathAddArcToPoint, 
CGPathAddArc 

和其他

    #import <QuartzCore/QuartzCore.h>
    #define degreesToRadians(deg) (deg / 180.0 * M_PI)

manualy :

-(CGPoint)setPointToAngle:(int)angle center:(CGPoint)centerPoint radius:(double)radius
 {
    return CGPointMake(radius*cos(degreesToRadians(angle)) + centerPoint.x, radius*sin(degreesToRadians(angle)) + centerPoint.y);
 }

with animation something like this:

    int angle = 0; // start angle position 0-360 deg
    CGPoint center = self.view.center;
    CGPoint start = [self setPointToAngle:angle center:center radius:radius]; //point for start moving
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, start.x, start.y);

    for(int a =0;a<4;a++) //set path points for 90, 180, 270,360 deg form begining angle
    {
        angle+=45;
        expPoint = [self setPointToAngle:angle center:center radius:expRadius];
        angle+=45;
        start = [self setPointToAngle:angle center:center radius:radius];
        CGPathAddQuadCurveToPoint(path, NULL,expPoint.x, expPoint.y, start.x, start.y);
    }

    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.removedOnCompletion = NO;
    pathAnimation.path = path;
    [pathAnimation setCalculationMode:kCAAnimationCubic];
    [pathAnimation setFillMode:kCAFillModeForwards];
    pathAnimation.duration = 14.0; 

    [MY_VIEW.layer addAnimation:pathAnimation forKey:nil];

also look at

CGPathAddQuadCurveToPoint, 
CGPathAddCurveToPoint, 
CGPathAddArcToPoint, 
CGPathAddArc 

and others

抚笙 2024-11-07 11:11:05

放入动画线程并在每一帧手动移动它并不是什么大问题,所以这就是我所做的。

Its not that big a deal to put an animation thread in and move it manually every frame so thats what I went with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文