2

I want to achieve the following by code:

enter image description here

Based on a circular path or arc, I need to place other views evenly around the perimeter.

Is this possible without hardcoding the frames? If so, how? In addition to that, can I make a view to follow a path ? if so, how?

Update: I found this answer helpful, but it seems to use a lot of code though... Place images along a bezier path

Community
  • 1
  • 1
Omer
  • 5,470
  • 8
  • 39
  • 64
  • Yes and yes, you can do both. – matt Sep 25 '15 at 18:42
  • Please don't include unnecessary or false tags. When you have said "ios" you have implied "iphone" and "cocoa". This has nothing to do with "xcode". I have left "objective-c", however, because it indicates what language you'd like code to be in. – matt Sep 25 '15 at 18:43
  • Got it, thanks. BTW, I'm modifying my question, the idea is to have an answer of how to do it, not intended to be a Y/N question – Omer Sep 25 '15 at 20:22
  • I've explained how to do it and I've added a screenshot to show that it works. – matt Sep 26 '15 at 00:02

1 Answers1

3

It's easy. A view is a layer.

A layer is positioned by its anchor point. So place the layer's anchor point at the center of the circular path, and define the anchor point at a sufficient size to move the layer away from the center to lie on the desired radius.

Moreover, a layer is rotated around around its anchor point, so now just apply a rotation transform in an increment of nths of a circle, where, n is the number of views.

As you can see, I can easily draw your sub-circles evenly spaced out, given any number of desired sub-circles:

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Hey, thanks you! ... but I need the center of the views to follow a path just in case it is deformed into a elipse or other shapes. – Omer Sep 28 '15 at 12:30
  • 1
    You never said that in your question, though. I answered the question you asked. I'm not a mind reader. – matt Sep 28 '15 at 13:02
  • That's true, sorry for taking a minute of your time. BTW, there's no need to be rude man. – Omer Sep 28 '15 at 14:09