Question

I am having one issue about CATransform3D.

I have a view A, which contains a label B. B's layer position is the center of A. B is used to display notification messages. I want to rotate A by 180 degree, of course the text in B will be upside down. So I have to rotate B by 180 degree too. Everything seems straight forward and actually in the simulator it works fine.

But when I loaded on the device, A and B did rotate, but B's position was changed. Now I can only see half of B, the other half is out of A.

My guess is that, when rotating A, because B is related to A's coordinate system, which was flipped 180 degree, B's location is changed.

But I want to know if anybody has ideas how to fix this problem or if you guys have better ways to approach.

Thank you very much.

UPDATE

I still can't figure out why B's position gets shifted, but I came up with another method to implement the same animation. A little bit tricky.

The key is animation.autoreverse, we know that when you rotate the label's super view by Pi, the text in the label will be rotated upside down. So what I did was rotate the super view by Pi/2, keep the same duration and set autoreverse = YES, what it will do is that it will rotate the super view by Pi/2, then rotate it back to the initial state. The result turns out that the view isn't get rotated at all, but for the user's vision, it is rotated.

Was it helpful?

Solution

I've found that subLayers and subviews of views don't always respond well to doubled animations (esp. alpha and center changes). If you must (as it is a little more expensive than normal), use UIViewAnimationOptionAllowsAnimatedContent, which will force a redraw instead of a 'snapshot' that is animated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top