Tum
Tum

Reputation: 7595

Skew image in Objective C

I want to skew an image in objective C like pictured below, is this possible using CGAffineTransform? I'm not sure how to achieve such an effect and so far only get it to rotate or scale.

skew img

Upvotes: 0

Views: 1187

Answers (1)

user3386109
user3386109

Reputation: 34839

You can do it using the transform property of a layer, since a layer's transform is a 3D transform. In the code below, the anchor point of the layer is moved to the left edge, and then the 3D transform is applied. Note that self.anim3DView is just a standard UIImageView.

if ( self.anim3DView.layer.anchorPoint.x > 0.0 )
{
    CGPoint position = self.anim3DView.layer.position;
    position.x -= self.anim3DView.layer.bounds.size.width / 2.0;
    self.anim3DView.layer.anchorPoint = CGPointMake( 0.0, 0.5 );
    self.anim3DView.layer.position = position;
}

CATransform3D t = CATransform3DIdentity;
t.m34 = -0.005;
t = CATransform3DRotate( t, M_PI / 6.0, 0.0, 1.0, 0.0 );
self.anim3DView.layer.transform = t;

Upvotes: 2

Related Questions