沿iOS中的路径均匀间隔绘制图像 [英] Draw images evenly spaced along a path in iOS

查看:142
本文介绍了沿iOS中的路径均匀间隔绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是将手指移过屏幕(touchesMoved)并沿着touchesMoved生成的点绘制均匀间隔的图像(可能是CGImageRefs)。我可以绘制线条,但我想要生成的东西看起来像这样(对于这个例子我使用箭头的图像,但它可能是任何图像,可能是我的狗的照片:))主要的是用手指在iPhone或iPad上绘图时,图像均匀分布。

What I want to do is move my finger across the screen (touchesMoved) and draw evenly spaced images (perhaps CGImageRefs) along the points generated by the touchesMoved. I can draw lines, but what I want to generate is something that looks like this (for this example I am using an image of an arrow but it could be any image, could be a picture of my dog :) ) The main thing is to get the images evenly spaced when drawing with a finger on an iPhone or iPad.

推荐答案

假设您已经拥有跟踪用户触摸的代码在屏幕上移动他们的触摸,听起来你想要检测他们何时移动了等于图像长度的距离,此时你想要在他们的触摸下绘制另一个图像副本。

Assuming that you already have code that tracks the user's touch as they move their touch around the screen, it sounds like you want to detect when they have moved a distance equal to the length of your image, at which time you want to draw another copy of your image under their touch.

为实现这一目标,我认为你需要:

To achieve this, I think you will need to:


  • 计算你的长度(宽度)图片

  • 实现代码,将图像副本绘制到视图上,旋转到任意角度

  • 每次用户访问uch移动(例如in touchesMoved :):

    • 计算每次移动时触摸的增量并生成该delta的长度(例如sqrt(dx ^ 2 + dy ^) 2))

    • 累积自上次拍摄图像以来的距离

    • 如果距离已达到图像的长度,请绘制一份触摸当前位置下的图像,适当旋转(可能根据从最后一个图像的位置到当前位置的向量)

    • calculate the length (width) of your image
    • implement code to draw copies of your image onto your view, rotated to any angle
    • each time the user's touch moves (e.g. in touchesMoved:):
      • calculate the delta of the touch each time it moves and generate the "length" of that delta (e.g. something like sqrt(dx^2 + dy^2))
      • accumulate the distance since the last image was drawn
      • if the distance has reached the length of your image, draw a copy of your image under the touch's current position, rotated appropriately (probably according to the vector from the position of the last image to the current position)

      听起来怎么样?

      这篇关于沿iOS中的路径均匀间隔绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆