How to draw a line of shapes in swift

I am porting an android music score application over to iOS, using swift and SwiftUI.

One of the elements of music notation is a glissando.

The form of this line can be seen here. - could not see how to add an image here.

When I draw the glissando in the android app, I can create a shape which represents a single "wave" of this line and then use it as a stamp which is repeated by the graphics system along the defined path, in this manner :

m_StampPath = new Path();
m_StampPath.moveTo(...);
m_StampPath.cubicTo(...);
m_StampPath.cubicTo(...);
...
m_StampPath.close();

m_WavyLine = new PathDashPathEffect(m_StampPath, fStampOffset, 0.0f, PathDashPathEffect.Style.MORPH);

// this is a Paint object
pt.setPathEffect(m_WavyLine);
pt.setStyle(Paint.Style.STROKE);

LinePath = new Path();
LinePath.moveTo(...);
LinePath.lineTo(...);

canvas.drawPath(LinePath, pt);

How can I achieve the same thing within swift, taking into account that the angle of the line is not always the same ?

Replies

In SwiftUI...

You can draw in a View, using a Path

Path has methods (that you should find familiar) like:

move(to:)
addLine(to:)
addCurve(to:control1:control2:)

To get the rotation, you could then use the View modifier:

rotationEffect(_:anchor:)

You could draw this over another view using a ZStack, or by using the "overlay" View modifier

  • This will not use the "stamp" image as the line, however. Sorry, but I don't see how this answers my question.

  • No need to be rude. I took time out from my day, to show you code that could be used to create the stamp.

  • @Expression-Lannion-France, you have not shown any code in Swift. How would readers know what sort of thing would answer your question?

Add a Comment

@robnotyou, I am sorry that you felt I was being rude, that was not my intention. I can already create the stamp in swift, that's not a problem - its using it to create a continuous "line" of stamps. @OOPer, my question stated that I am using swift a couple of times and I gave the equivalent code in java to illustrate my need - thought that was sufficient info.

  • thought that was sufficient info. > You though it was sufficient, but actually it was not. Unless you could provide enough info, no one would not be able to answer your question.

Add a Comment