Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone skew a CALayer

Tags:

iphone

calayer

I'm a beginner and I am doing some exercises to familiarize myself with CALayer ...

I just want to know how to "incline" (or skew) a CALayer 45° angle ?

Thank you.

like image 309
MaRiriAndMe Avatar asked Nov 27 '22 14:11

MaRiriAndMe


1 Answers

CALayers have a property, affineTransform that takes a CAAffineTransform. That documentation explicitly notes that:

Scaling, rotation, and translation are the most commonly used manipulations supported by affine transforms, but skewing is also possible.

(emphasis mine, obviously)

There's no built in helper to construct a skew transform, but you could do something like (untested):

CGAffineTransform CGAffineTransformMakeSkew(CGFloat skewAmount)
{
    CGAffineTransform skewTransform = CGAffineTransformIdentity;
    skewTransform.b = skewAmount;
    return skewTransform;
}

Then, for a skew such that things that were verticals stand at 45 degrees to the horizontal you'd use:

layer.affineTransform = CGAffineTransformMakeSkew(1.0f);
like image 129
Tommy Avatar answered Dec 10 '22 13:12

Tommy