Animation in quartz 2D - iphone

I want to create an app which after each 1 second will show 4-5 words on screen but the last word will zoom out/in. I can easily create static words and for the last animating word i need to draw the static again n again.
How can i create 2 separate layers so the static text is on one layer ( i will fill it after each second) and the last word (animated one) will be on other layer.
How to create 2 separate layers? Attached on same screen but handling their drawRect method separately?

If I have understood your query then you should make your own class which will be subclass of UIView and override drawRect method in the implementation, then create 2 objects of your custom UIView class at the place where you are making layer's object. you can have x,y co-ordinate variables which will work separately for both layers....

Related

Is it possible to animate individual draw calls in a CALayer?

I'm drawing in a single CALayer between 100 and up to 1000 dots (colored circles actually) in a grid, when each dot state changes from hidden to shown and viceversa. So this layer is drawn quite a lot. The reason I went with a single layer and not 1000 layers is because I think performance would be hit with so many layers. Now I want to animate the dissappearance of (maybe multiple) dots over 2 seconds, a fade-off. Is that possible to do for each individual draw call?

Flutter - How to move and zoom Canvas drawings without AGAIN running something like the CustomPainter paint method?

I have tried using the methods "Transform.scale" (for "zooming" ) and "Transform.translate" (for the moving), but they seem to trigger the paint method in the CustomPainter.
(even though the method "shouldRepaint" returns false, but that method is not even invoked)
Maybe there is some other way of doing what I want i.e. be able to move and zoom something I have created with a Canvas (without again executing the paint method)?
In the below example code there are three sliders, one for zooming out (i.e. reducing the size) and one for moving horizontally and one for moving vertically.
The "paint" method simply draws a polygon (see the below attached screenshot picture).
While the example code below is simple (i.e. small amount of hardcoded vector data and fast to render), I want to emphasize that the solution I am looking for need to support MANY complicated drawings (with LOTS OF data, slow to render), i.e. it is not an acceptable solution to suggest something like instead manually converting this one vector image to a raster image (e.g. PNG/JPG/GIF).
Below I try do describe how you can think regarding a scenario that need to be supported:
Imagine you want to implement an app with a huge dropdown list with lots of different vector data images to be selected.
The data of those VECTOR images may be retrieved from the internet or from a big local SQLite database.
IMPORTANT: The DATA in those images are NOT raster images such as jpg, png, gif... but the VECTOR data to become retrieved is defined as lots of screen coordinates for points, lines, polygons, and textual labels, and icons, and color values... and so on.
Such VECTOR data will then be used for creating the image, and as far as I understand you should use CustomPainter with the paint method unless there are better options?
Also imagine that each of such selected image with vector data is HUGE with MANY THOUSANDS of lines, polygons, icons, ... and so on, and that the paint method might take seconds for creating the image.
BUT, once it is drawn the data will not change.
So, since the "paint" method might take seconds to render a huge amount of vector data, you want to avoid invoking it frequently, when moving or zooming.
Therefore I think it would be desirable if it would be possible to use the method "shouldRepaint" to return false, but it seems as that method is not even invoked at all when resizing or moving with the Transform methods "scale" and "translate".
But maybe there is some other solution to support the above described scenario, maybe some other class than CustomPainter that do not automatically trigger the paint method when applying Transform scale/translate ?
I hope there is a solution with the Flutter framework somehow being able to automatically reuse the bitmap (e.g color values at certain bits and bytes) that was created potentially slowly with a paint method but can scale/zoom and move it in a faster way than having to execute the paint method again.
If you just want to zoom, scale, pan on your images, then you can try the new InteractiveViewer widget.
InteractiveViewer class
A widget that enables pan and zoom
interactions with its child.
The user can transform the child by dragging to pan or pinching to
zoom.
https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html

SpriteKit grand-children of views overlap zPosition

I've started implementing an iOS game with swift and SpriteKit.
I have an object called "bubble" which basically is an SKSpriteNode (with zPosition=0, with image) that have a child (which is an SKCropNode of a person image cropped to a circle, with zPozition=1).
That's ok if one bubble covers another bubble as a whole, but somehow it seems like the bubbles are partially covered with the person images.
a demo picture is provided: (my final output should be that bubble1 will be on top of child-of-bubble-2)
Maybe the problem is that SpriteKit ignores child ordering and just set any node with a zPozition to be in it's correct place? That is - all the bubbles are drawn first because they have zPosition=0 and then all the bubble-children are drawn, as they all have zPosition=1?
If this is the case, what can I do to make sure all bubble parts are drawn together (and other bubbles can cover that bubble, I don't care) knowing that I have a dynamic amount of bubbles?
well according to this SO answer, indeed all the zPosition values are calculated before drawing.
I ended up creating a counter for bubbles, adding 1 every time a bubble has been added, and assinging the counter value as its zPosition.
And inside the bubbles, I made sure every child has a zPosition in the range (0, 1)
If you need to draw things in a precise order, then I suggest you to read section Understanding the Drawing Order for a Node Tree of SKNode Apple's documentation. Everything is correctly describe in details.

How can I move a UIView, but leave its content positions unchanged relative to the superview?

A UIView has 2 images as sub-views, and clip to bounds set to yes.
I want to move the UIView in an animation block, but have the sub-views not move with the parent. If the view was to move 50 points to the right, more of the second image would be seen, and less of the first.
I can move the view manually, and update the subview positions opposite the new view position, but I can't figure out how to achieve the same thing in a block.
I think the limitation you're running into has to do with the fact that UIView Animation blocks use Core Animation under the hood, and Core Animation animates a 'presentation' layer which is a copy of the original view/layer that the animation was scheduled on. So during your block's animation, the presentation layer's position is changing, but the position of the model view remains unchanged.
Since you mentioned that you can update the view position manually (and subview positions in the opposite direction) to achieve the desired effect, consider creating an NSTimer at animation schedule time that runs 60 times per second (to try and catch every animation frame) that simply queries the presentation layer for its current position (as set by the animation itself + any special timing functions specified as argument to the animation), and perform your work to update the underlying model to match that.
You should be able to query the animated layer's position with:
yourUIView.layer.presentationLayer.frame.origin
Then add a completion block to your animation that invalidates the timer.
Before you can access the view's layer property, you must add to your project the
QuartzCore.framework
Cheers,

is there MouseChildren for CALayer hit test?

Hey.
i have a main layer that contains a 4 circle layers and inside each circle there is a text layer :
main layer -> (4)circle layer -> (1)textLayer.
I am performing hit test on the main layer and i want to receive the circle that was clicked.
It works fine, but when I tap in the text area i get back the text layer and not the circle layer.
In AS3 you have
MouseChildren = true/false.
How can i get this functionality in objective c?
thanks
shani
Just use the superlayer property, like this:
if([theLayer isKindOfClass:[CATextLayer class]])
theLayer = theLayer.superlayer;
In other words, if you've already got the circle layer, theLayer doesn't change; if it's one of the text sublayers, theLayer changes to point to the layer that contains that sublayer.