在 iOS 上绘制正弦波
我想在自定义 UIView 中绘制幅度变化的正弦波。振幅值通过计时器每 1/30 秒改变一次。正弦波本身和动画应该看起来很平滑。 目前我正在尝试使用 CGContextAddCurveToPoint 来完成此操作,曲线非常平滑,但曲线连接的点相当难看。
我还可以通过计算每个点的正弦函数,然后通过从一个点移动到另一个点来绘制它,但它可能很容易改变幅度,但有点像素化。
我真的不知道最好的方法是什么。它必须美观、快速且易于操作。或者也许有什么我忘记了?
我真的希望有人能帮助我。
I want to draw a sine wave with changing amplitude in a custom UIView. The value for the amplitude is changed through a timer every 1/30s. The sine wave itself and the animation should look smooth.
At the moment I'm trying to do it with CGContextAddCurveToPoint, the curve is pretty smooth, but the point where the curves are connected is rather ugly.
I could also do it by calculating the sine function for every single point and then draw it by moving form one point to another, but it will probably easy to change the amplitude, but a bit pixelated.
I don't really know what's the best way to do it. It has to be nice-looking, fast and easy to do. Or maybe there's something I've forgotten?
I really hope someone can help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以使用一个
UIBezierPath
类?如果您的应用程序是图形密集型的,您也可以使用 OpenGL。另外,我认为 Quartz Composer 也可以让你制作正弦波。
I think there is a
UIBezierPath
class that you could use?You could also use OpenGL if your app is graphics-intensive. Also, I think Quartz Composer will let you do sine waves too.