sorry for stupid question, i need to animate all sublayers in some particular layer. How to iterate through all the sublayers?
You can iterate sublayers of a layer via for-in loop
for child in layer.subLayers
child.animate
properties:
x: Utils.randomNumber(100)
y: Utils.randomNumber(100)
if you need an index of each sublayer, you can change loop like this
for child, i in layer.subLayers
I came across this question looking for a similar solution. I wanted to change all subLayers in a given layer, even deep nested layers. In the Docs I found descendants. Adding here in case someone is looking for a solution to iterate all nested subLayers.
for descendant in layers
descendant.ignoreEvents
Related
I've been having a little success with NSAffineTransform but have come across AffineTransform which is presumably more Swifty. However it doesn't have a concat method, so how do you use it? I'm aiming to draw the same little BezierPath rotated several times round the centre.
Sorry if it's obvious; I guess others might find this useful.
Here's how I see it. If you're drawing with an NSBezierPath you apply it to the path with myPath.transform(using: tr), e.g.:
let tr1 = AffineTransform(translationByX: 20, byY: 20)
bez = NSBezierPath()
// add some elements to the path here
bez.transform(using: tr1)
bez.stroke()
As I see it, the transform affects all the elements already in the path, but not any elements subsequently added. Transforms are cumulative, in that re-applying a transform, or applying another will affect all the elements so far entered.
You can also use the AffineTransform's own methods to transform individual points or sizes.
I have a list of items in a server. These items have scores and the scores correspond to the size of their view (a circle). I would like to depict these items with the largest circle in the center and each successively smaller circle wrapping around it, spiralling smaller and smaller.
Once I achieve this I would like to set it to a scroll. A scroll up will add each successively larger item to the center of the spiral and eventually spiralling down and away and vice versa.
The sizing of these objects I have performed already.
Here's my methodology: Native Swift doesn't have anything to help me layout-wise here to my knowledge. V/HStack won't help and neither will ScrollView. Essentially my understanding is that I should create a path that calculates its spiral based on the sizes of the items and these items should use .offset to position themselves on the path. Using a DragGesture, I can attach a #State variable to determine how far down the path each item is.
This is by far the most complex UI I've attempted so anything to get me down the right path is appreciated.
Edit 1:
Here is the ideal UI:
I'm sure there are various ways to approach this.
Dragging the "top" view down using a UIPanGestureRecognizer - and Scaling it during the drag - is pretty straight-forward. Getting the "already dragged" views to animate around the center is a bit tougher.
One approach is to use a UIViewPropertyAnimator and creating Key Frames for the positions around the arc.
Additional advantages to that include fewer calculations (set scaling and position key frames in .began state) as well as being able to "scrub" through the animation.
I put together a little demo that ended up looking like this:
You can play with the source code here: https://github.com/DonMag/OrbitDrag
When I use the following code to go through all the layers in a leaflet map,
map.eachLayer(function (layer) {
console.log(layer);
});
I just wants what rule is used to create this order. Is it because of the ZIndex of the layer? Or is it because the layer is added in different time? If the layer is added early, it will be in the bottom.
Thanks,
Good question, it seems the LeafletJS docs don't say anything about the ordering of the layers via eachLayer, so...
Looking at the code on github, L.Map.eachLayer loops through L.Map._layers which is an object (not an array). So technically the layers could come back in any order...
That said, the individual layers are added to the _layers object in the order they are added to the map. So in all likelihood, eachLayer will be iterating over the layers in that same order (whatever order they were added to the map).
My view have multiple CA layers arranged like UITableView Cells. I have created the layer dynamically one after other in a top down order.
But I want to create a layer between the two layers, I want to create the layer between two layers when I pinch out between two layers. How can i do that.
I am new to this, so any help or direction to something closer would be great.
...
Thanks in Advance..
You can use one of the CALayer methods
- (void)insertSublayer:(CALayer *)aLayer atIndex:(unsigned)index
- (void)insertSublayer:(CALayer *)aLayer below:(CALayer *)sublayer
- (void)insertSublayer:(CALayer *)aLayer above:(CALayer *)sublayer
to insert a new layer at a specific point in the sublayers array.
dont know if I get it.. but when you create the layers, make sure they are in the same layer tree (sublayers (or subsublayers) of the same layer)
so l1 has l2 has l3
then the zorder would be there already
now you have l_parent has {l1 and l2 and l3 and l4} ... lx are siblings
TODO:
set the zindex of the layers
After digging alot here and there, I got my answer from an Example here.
It not just gave me my answer, I actually learned some new stuff about CALayer and core animation, some of its details are here
I have a CALayer with 9 sublayers, which occasionally flip vertically and I use CATransform3D to do so. Now, my problem is that, sometimes, I need to apply a transformation to the super layer of those 9 layers. When I do that, the position and transformation of the sublayers gets all screwed up. Is there a way to ignore the transform of the parent layer, so that it doesn't affect the sublayers?
The whole point of the layer tree is to inherit attributes like transforms. If you don't want certain layers to inherit from their parent, insert them as another layer's children.
You could also apply the inverse transform to the child layers, but that would be hackish, compute-intensive, and open the door to rounding errors.