I want to achieve the following by code:
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
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:
Related
I've imported a vector layer from a psd into paint code v1, I'm trying to create a background image and make it universal.
I can't seem to add a frame around the vector, to complicate matters, I only need a portion, the center, of the layer. (The design is based around a circle, it has lines drawn towards the center of the circle.)
I can’t seem to add a frame to dynamically resize the part I need.
I found this http://www.raywenderlich.com/36341/paintcode-tutorial-dynamic-buttons the part about frame ans groups doesn't help me....
When I add a click frame and drag it around the area I need, it's at the same level as the vector layer. I've also tried adding a group around both, but that doesn't seem to obey the frame size either.
I’ve looked through the tutorials and googled adding a frame, but I can’t seem to achieve what I need.
EDIT
A frame is supposed to be at the same level as the vectors you're working with.
All you do then is set the resize rules of your vectors. There is a little rectangle in the frame's parameters interface with straight arrows and springs that you can modify to fit your wishes.
I think I also remember a checkbox setting to resize only what's inside the frame.
Now I haven't used PaintCode for a while, but if this doesn't help you, there probably is a problem with your vector layer.
I don't know if this information helps.
But if you resizing doesn't work as you expected. Look carefully at the transformation box (the one with the springs attached). When you have put a frame around your object. The middle dot in this box should be blue instead of green. if t's green, you may have a problem with the originating point of your objects and then the resizing may not work as you expected.
I would like UIButtons to arc around a center point.
The image below shows the end result I would like, where all of the grey elements are buttons. Optimally, I would like math that supports an arbitrary amount of buttons arced around the same center, and distribute space evenly.
Can this be done with standard elements? Do I need to create a single custom shape and use as a button? Or will I need a custom shape for each of the buttons below?
You can use CAShapeLayers, each having a path that's constructed out of concentric arcs, with a fillColor. You can achieve the gap by incrementing the angle by a delta amount for each sector.
Edit: Alternatively you can create just one path, and apply a rotation transform on copies of it around the center.
Checkout this Github - https://github.com/Planet1107/CustomShapedButtons/. I think it demonstrates exactly what you need.
Below is a screenshot from a famous structure building game.
As you can see rods are attached together with ball joints. I'm trying to achieve something similar with Cosos2d on iPhone. I've got two questions here:
Should I draw those ball joints or should I just add them as sprites?
I guess the rods are not drawn bur are rather images. But considering that the length of the rods will change depending on need, how do I make rods with different lengths from just one image?
I am not sure what would be the best approach for one. I would imagine that either way would be fine, but it would be harder to achieve whatever visual affect you want through drawing them. I think the hardest part would be making sure that they are anchored to vertices in a grid system that has the dimension that you want.
As for (2) you can always scale your image.
CCSprite *rod = [CCSprite spriteWithFile:#"rod.png"];
rod.scaleY = 2.0; //or scaleX
Then rotate and change its anchor points as needed.
Again I imagine the most difficult part would be anchoring them and positioning them correctly, so that align properly with the vertices.
Here is a picture:
Is there a way to expand layer (the area where you draw), to be larger.
At first i thought that (0,0) is the center, but it seems that it is a starting point for layer.
I was planning to draw content at (0,0) then to translate it as necessary.
Or, must i draw whatever i have in center of layer (width/2, height/2) and then translate as necessary?
EDIT_01:
The offset of layer is made by panning gesture recognizer. That is on purpose, since app must have panning of content.
Answers
At first i thought that (0,0) is the center, but it seems that it is a starting point for layer
(0,0) in iOS begins at the top left of the layer, and gets greater going right and down. In OS X, (0,0) begins in the bottom left, and gets greater going right and up.
Is there a way to expand layer (the area where you draw), to be larger
The question I have is, do you need to? This can have performance issues, as you're rendering and storing drawing data when you don't really need to, causing more memory to be used. It looks like your layer is filling the screen correctly, it's just translated incorrectly. If you move it to the correct place, you shouldn't need to expand the layer off screen.
This doesn't mean you can't translate other layers off screen, of course you can. But really you don't want to expand the size of your drawing area to expand off screen.
Must i draw whatever i have in center of layer (width/2, height/2) and then translate as necessary?
If you want them drawn into the center, then yes. You can create your own method to translate your own co-ordinate space into the co-ordinate space of the layer, to make this easier for you.
Documentation
I'd suggest reading this, to get a greater grasp of the geometry workings of CALayer:
https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html#//apple_ref/doc/uid/TP40006082-SW1
...and this to get an understanding of drawing techniques:
https://developer.apple.com/library/ios/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_layers/dq_layers.html
I would like to create a circular path that has animated .gifs along the path, though I would like them all to be facing the center of the circle.
I would also really like it if the circular path could scale with the window width and height.
Which would add or subtract .gifs to the circle.
Is this possible?
Example jpg..
http://oi48.tinypic.com/5nitt4.jpg
I don't think SVG supports animated .gifs. But everything else is possible--you just need a bit of trigonometry to position and scale your elements in the way you want them to be displayed!
Edit: As per the comments below, animated gifs are in fact supported.