Re: Swift: Draw a circle with tic marks at it's edge?
Re: Swift: Draw a circle with tic marks at it's edge?
- Subject: Re: Swift: Draw a circle with tic marks at it's edge?
- From: Quincey Morris <email@hidden>
- Date: Thu, 19 Jan 2017 10:11:46 -0800
- Feedback-id: 167118m:167118agrif8a:167118sXW6Sbw1j9:SMTPCORP
On Jan 19, 2017, at 05:48 , Eric E. Dolecki <email@hidden> wrote:
>
> However, the position of the ticks
> is off. Seems like it needs to be moved down 1/2 way and the same to the
> right.
The position of the ticks is correct as you calculated, since you calculated relative to the view origin, which is at the upper left of the view bounds rect. (If you squint at the image carefully, you can see that it’s correct, showing the first and last ticks, with the rest being off the view to the left and top.) All you need to do is offset the x and y coordinates by the distances to the center of the view.
However, your image demonstrates a subtler bug which is something you need to deal with no matter how you end up drawing the view. Note that the visible horizontal tick in your image is clipped to the view bounds, so the line segment appears to be only half of the correct thickness. To get everything drawn properly, your drawing needs to be inset slightly from the edges of the view bounds. You have to ensure that there is sufficient inset to provide for:
a. the line thickness, when stroking a path
b. the end caps, when stroking a path
c. anti-aliasing, when drawing near the edges of the view bounds
Considerations such as those are why I suggested earlier as thinking of the drawing geometry as something different to the view geometry. Similar considerations apply to input, when your view is intended to be responsive to touches. If your drawn elements (the parts the user “grabs”) are too close the edge of the view, they can be hard to grab because the initial touch has a good chance of being passed to a different view.
Even if you’re using pre-rendered images instead of doing the drawing via bezier paths, you still have to consider the effects of bounds clipping on your drawing and touch interactions.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden