ios - 在曲线中移动 UIImageview

标签 ios objective-c uiimageview uikit

我正在尝试添加图像并将其移动到曲线路径上。我有一个值为 0 到 100 的半圆。我想用值移动该图像。

这是我的曲线进度条的图片 我想在那条线上旋转指针。

如果我尝试贝塞尔曲线,我将无法发现我的指针。它会从头到尾动画。

Any help how can i animate this.? 

谢谢

enter image description here

最佳答案

使用以下代码片段制作半圆路径。用您需要使用的针替换旋转按钮,并提供移动针的角度。我正在将此代码用于速度计。希望这对您有所帮助。

- (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];
}

你可以这样调用这个函数:

   [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];
    });

这样你就可以达到你想要的结果。

关于ios - 在曲线中移动 UIImageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24280510/

相关文章:

ios - 为什么在创建变量时点击手势识别器不起作用?

ios - 无法为 Quickblox 框架加载 info.plist 包

ios - 在 NSString 中查找各种子字符串

objective-c - 从 Info plist 获取数据

swift - 在 ContextMenu 中更改 UIImage 的弹出窗口大小?

ios - TableView 单元格中的 ScrollView 将无法正确显示图像,并且 swift 4 中的分页模式下有一页额外的页面

javascript - Cordova 仅在恢复事件后执行插件

iOS 13 替代 'setAnimationCurve'

Objective-C NSMutableArray removeObjectAtIndex : crashes

objective-c - objective-c : Go Back to Page 1 Button