ios - Trying to draw multiple circles but both circles connect with a line -


i drew circle when try add circle line connects both circles.

import uikit  class skills: uiview {      override func drawrect(rect: cgrect)     {         var startangle: float = float(2 * m_pi)         var endangle: float = 0.0         var endangletwo: float = 2.0          // drawing code         // set radius         let strokewidth = 10.0         let radius = cgfloat((cgfloat(self.frame.size.width) - cgfloat(strokewidth)) / 20)           // context         var context = uigraphicsgetcurrentcontext()            **// find middle of circle         let center = cgpointmake(100, 200)          let inside = cgpointmake(100,400)**          // set stroke color         cgcontextsetstrokecolorwithcolor(context, uicolor.whitecolor().cgcolor)          // set line width         cgcontextsetlinewidth(context, cgfloat(strokewidth))          // set fill color (if filling circle)         cgcontextsetfillcolorwithcolor(context, uicolor.clearcolor().cgcolor)          // rotate angles inputted angles intuitive clock face: top 0 (or 2π), right π/2, bottom π , left 3π/2.         // in essence, appears unit circle rotated π/2 anti clockwise.         startangle = startangle - float(m_pi_2)         endangle = endangle - float(m_pi_2)         endangletwo = endangletwo - float(m_2_pi)          // draw arc around circle         cgcontextaddarc(context, center.x, center.y, cgfloat(radius), cgfloat(startangle), cgfloat(endangle), 0)          cgcontextaddarc(context, inside.x, inside.y, cgfloat(radius), cgfloat(startangle), cgfloat(endangletwo),0)          // draw arc         cgcontextdrawpath(context, kcgpathstroke) // or kcgpathfillstroke fill , stroke circle            }           } 

i think problem //find middle of circle because when swift detects cgpointmake connect 2 points? think, i'm not sure. how fix this?

from cgcontextaddarc() documentation:

if current path contains subpath, quartz adds line connecting current point starting point of arc. if current path empty, quartz creates new subpath starting point set starting point of arc.

therefore have "move to" initial point of circle first:

cgcontextmovetopoint(context, center.x + cgfloat(cos(startangle)) * radius, center.y + cgfloat(sin(startangle)) * radius) cgcontextaddarc(context, center.x, center.y, cgfloat(radius), cgfloat(startangle), cgfloat(endangle), 0)  cgcontextmovetopoint(context, inside.x + cgfloat(cos(startangle)) * radius, inside.y + cgfloat(sin(startangle)) * radius) cgcontextaddarc(context, inside.x, inside.y, cgfloat(radius), cgfloat(startangle), cgfloat(endangletwo),0) 

(you need less type conversations if use cgfloat consequently instead of float/cgfloat` mixture.)

alternatively use cgcontextaddellipseinrect() draw full circle.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -