iOS - Using the same vanishing point for multiple elements when using CATransform3d - ios

I'm trying to rotate multiple elements using CATransform3d, the problem is that each one is assigned an individual vanishing point. Since they are dynamic elements I cannot use an image to simulate all of them moving together. And I know no way to move them as a group.
Here is an image that clearly shows the issue and the expected outcome. Visual Description
Already tried every solution I could find and nothing is working for me.
Cheers.

I don't understand why you can't put all of them into one view, and then just use the CATransform3d on the containing view? I've done this before with exactly the result you are looking for. Just a simple add them all as subviews of a view and then perform your CATransform3D on the view.

Related

How to use globalCompositeOperation in Konva for multiple shapes with scaling

I'm trying to create polygons with an inner border in Konva.
I found this example of doing this with globalCompositeOperation which works well in Konva, as long as there is only one shape. As soon as I try to add a second shape, this obviously doesn't work anymore and the first shape disappears.
It would work if I were to use a different layer for every shape, but of course that's not a solution that scales well.
I tried using a temporary layer as is done in the example but couldn't get it to work.
So I found this example of using group.cache(), which works fine ... until I try to scale the stage, at which point I would have to refresh the cache, otherwise I only get the scaled up cache, which looks bad.
This codesandbox illustrates the problem. (Please note that this uses simple triangles, in reality I work with arbitray polygons)
So is there a way to use cache with scaling? Or alternatively a better way to use globalCompositeOperation with multiple shapes in the same layer? Or some alternative solution?
I found a solution: calling group.cache({pixelRatio: scaleFactor}). I updated the sandbox.
No idea, if this is the best solution, but it works.

Drawing a grid of circles in xcode/swift

How would I go abouts getting an effect in a view controller like the wonderful work of art attached in the following link?
Circles
I do have some idea, ranging from actually using ASCII text (I know, super wrong way) to a collection view of pictures, to what I suspect is the "right" way, done with core graphics. But I am asking in case there is a super easy/right methodology I will one day discover and facepalm.
You are correct that there are two primary ways for you to draw a grid of circles.
The primary way is to draw them using UIBezierPath or by using a collection view of images of circles.
For simple shapes, it is recommended that you choose the first option simply because your choices of circles aren't restricted by your images.
Here is a link for you to get started.

Apply definitely CGAffineTransform* to a UIView

I'm having a problem with scale transformation I have to apply to UIViews on Swift (but it's the same in objective-c too)
I'm applying a CGAffineTransformMakeScale() to multiples views during a gestureRecognizer.
It's like a loop for a cards deck. I remove the one on top and the X others behind scale up and a new one is added in the back.
The first iteration works as expected. But when I try to swipe the new front one, all the cards reset to their initial frame size because i'm trying to apply a new transform, which seems to cancel the previous one and reset the view to its initial state.
How can I apply definitely/commit the first transform change to be able to apply a new one after that based on the UIView resulting new size ?
I tried a UIView.commitAnimations() but no change.
EDIT :
Here's a simple example to understand what I try to do :
Imagine I have an initial UIView of 100x100
I have a shrink factor of 0.95, which means next views behind will be 95x95, then 90.25, then 85.73, etc
If I remove the top one (100x100), I want to scale up the others, so the 95x95 will become 100x100, etc
This is done by applying the inverse of the shrink factor, here 1.052631...
First time I apply the inverse factor, all views are correctly resized.
My problem is, when I trigger again by a swipe on the new front UIView a new resize of all views (So, for example, the 90.25x90.25 which became 95x95 should now scale to 100x100).
At this moment, the same CGAffineTransformMakeScale() is apply to all views, which all instantly reset to their original frame size (so the now 95x95 reset to 90.25x90.25, and then begin to apply the transformation on this old size).
As suggested here or elsewhere, using UIView.commitAnimations() in the end of each transformation don't change anything, and using a CGAffineTransformConcat() is like powering over and over the scaling by himself and of course views become insanely big...
I hope I made myself more clear, that's not easy to explain, don't hesitate to ask if something is wrong here.
After a lot of reading and consulting colleagues who know better than me about iOS programmation, here's my conclusion :
Applying a CGAffineTransformMakeScale() only modify visually a view but not its properties, and since it's difficult (and costly) to modify afterward the bounds and/or frame of a view, I should avoid to try to make a transform, update bounds, make another transform, etc.
Applying the same CGAffineTransformMakeScale() only reset the effect and not apply to the previous one.
Applying a CGAffineTransformScale() with the same values on top of the previous CGAffineTransformMakeScale() (or with a CGAffineTransformConcat()) has some unpredictable effect and will be very difficult to calculate precisely the new values to apply each time to get the effect I want.
The best way I can go with this is only applying one CGAffineTransformMakeScale() that I will keep updating scales values all along the view's life.
It implies now for me to rework all my implementation logic in reverse, but that's the easiest way to do this right.
Thanks all for your tips.

Flip Animation Using Core Animation Showing Reversed Contents

Here is the result that I get:
If I set the doubleSided property of layer 4 as No, the whole layer disappears. I know that already. But then, how can I show yet with correct content orientation?
Do the animation in two parts. At the halfway point, when the layer is side-on to the camera so you can’t see it, flip the layer the other way around and move the anchor point to the other side, and swap out the contents of the layer if you need to.
Unfortunately, I don’t have any sample code, because the last time I did this was on iOS 4, and the pile of hacks view-based animations that I was using don’t appear to work on layers any more. You could post your own code and accept your own answer if you want.

CATransform3D always becomes topmost view

I'am transforming one UIView's layer by using CATransform3D. The problem is that I can't display other controls (which are not subviews of this transformed view) above it.
For example this code:
[UIView flipTransitionFromView:self.standardImageView
toView:self.flippedImageView
duration:1.0f
completion:NULL];
[self.view insertSubview:flippedCloseButton aboveSubview:flippedImageView];
does not work - the flippedCloseButton is always behind the flippedImageView.
flipTransitionFromView is a method which merely makes the said 3d transformation.
Any ideas how to solve it are highly appreciated!
EDIT:
I kinda solved it myself by modifying the view layers' zPosition:
self.flippedCloseButton.layer.zPosition = self.flippedImageView.layer.zPosition + 1;
But is it the correct way to do this?
Andrius
I had a similar problem, but changing the zPosition did not solve it. The zPosition is used when giving a perspective to the layer (so that it looks smaller when z is larger), but not meant forgiving a visibility sequence I believe.
I do not fully understand what is happening, but when several sublayers are present at the same "Layer level", the question "what is visible" is not well- defined. I even had that part of a layer was visible and the other part was not.
I solved this in my case by putting the elements that have to be on top in the super layer. That ensures they are alway visible.
I am by no means a pro when it comes to Layers and animation, but in the course of educating myself, I made an App (PerspectiveTest) that explains some basics of how layer parameters and perspective work together. Might be of some help:
http://itunes.apple.com/nl/app/perspectivetest/id481006743?mt=8
Regards,
Voppe

Resources