Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can fake it this way: create an affine transform that collapse the layer along it's diagonal:</p> <pre><code>A-----B B | | / | | -&gt; A&amp;D | | / C-----D C </code></pre> <p>change the image, and trasform the CALayer back in another animation. This will create the illusion of the layer rotating around its diagonal.</p> <p>the matrix for that should be if I remember math correctly:</p> <pre><code>0.5 0.5 0 0.5 0.5 0 0 0 1 </code></pre> <p>Update: ok, CA doen't really likes to use degenerate transforms, but you can approximate it this way:</p> <pre><code>CGAffineTransform t1 = CGAffineTransformMakeRotation(M_PI/4.0f); CGAffineTransform t2 = CGAffineTransformScale(t1, 0.001f, 1.0f); CGAffineTransform t3 = CGAffineTransformRotate(t2,-M_PI/4.0f); </code></pre> <p>in my tests on the simulator there still was a problem because the rotations happens faster than te translation so with a solid black square the effect was a bit weird. I suppose that if you have a centered sprite with transparent area around it the effect will be close to what expected. You can then tweak the value of the <strong>t3</strong> matrix to see if you get a more appealing result.</p> <p>after more research, it appears that one should animate it's own transition via keyframes to obtaim the maximum control of the transition itself. say you were to display this animation in a second, you should make ten matrix to be shown at each tenth of a second withouot interpolation using kCAAnimationDiscrete; those matrix can be generated via the code below:</p> <pre><code>CGAffineTransform t1 = CGAffineTransformMakeRotation(M_PI/4.0f); CGAffineTransform t2 = CGAffineTransformScale(t1, animationStepValue, 1.0f); CGAffineTransform t3 = CGAffineTransformRotate(t2,-M_PI/4.0f); </code></pre> <p>where animationStepValue for ech of the keyFrame is taken from this progression:</p> <pre><code>{1 0.7 0.5 0.3 0.1 0.3 0.5 0.7 1} </code></pre> <p>that is: you're generating ten different transformation matrix (actually 9), pushing them as keyframes to be shown at each tenth of a second, and then using the "don't interpolate" parameter. you can tweak the animation number for balancing smoothness and performance*</p> <p>*sorry for possible errors, this last part was written without a spellchecker.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload