简体   繁体   English

在曲线中移动UIImageview

[英]Move UIImageview in Curve

i am trying to add Image and move it on curve path. 我试图添加图像并将其在曲线路径上移动。 i have half circle with value 0 to 100. And i want to move that image with value. 我有一个值为0到100的半圆。并且我想移动带有值的图像。

This is image of my curve progress bar I want to rotate the pointer on that line. 这是我的曲线进度条的图像,我想在该线上旋转指针。

If i try bezier curve i wont be able to spot my pointer . 如果我尝试贝塞尔曲线,我将无法发现我的指针。 it will animation from start to end. 它将从头到尾进行动画处理。

Any help how can i animate this.? 

Thanks 谢谢

在此处输入图片说明

Use the following snippet of code for making half circle path. 使用以下代码段制作半圆路径。 Replace the spin button with the needle you are required to use and provide angle to move the needle. 用您需要使用的针替换旋转按钮,并提供角度以移动针。 I'm using this code for speedometer. 我正在将此代码用于里程表。 Hope this helps for you. 希望这对您有所帮助。

- (void)spinButton : (UIView *)button : (float)angle
{

    button.layer.anchorPoint = CGPointMake(0.5, 0.5);

    CABasicAnimation *animation;
    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    // just for testing
    // angle +=200;

    if(angle >=360){angle = 360;}

    animation.fromValue = [NSNumber numberWithFloat:lastAngle];
    float m = angle/2 * (M_PI/180 );

    animation.toValue = [NSNumber numberWithFloat:(m)];
    // [CATransaction setValue:[NSNumber numberWithFloat:1.0] forKey:kCATransactionAnimationDuration];
    lastAngle =  m;
    // animation.duration = 1.0f;

    // to stop animation at last frame
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;

    animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
    animation.autoreverses = NO;
    [button.layer addAnimation:animation forKey:@"rotationAnimation"];
    [CATransaction begin];
    // [CATransaction commit];
}

You can call this functions like this: 您可以这样调用此函数:

   [self spinButton:btn :0];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self spinButton:btn :50];
    });

This way you can achieve your desired result. 这样,您可以达到所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM