Search code examples
ioscore-animationlayer

layer with angle


how can I draw a layer with a fixed angle, instead of horizontal like this:

CALayer *layer1 = [CALayer layer];
UIImage *image1 = [UIImage imageNamed:@"cuore2.png"];
[layer1 setPosition:CGPointMake(50,50)];
[layer1 setBounds:CGRectMake(10, 10, 40, 40)];
layer1.contents=(id)image1.CGImage;
[self.view.layer addSublayer:layer1];

Thanks a lot!


Solution

  • If you just want to display layer rotated by angle alpha (that is don't need any pseudo 3D perspective effects) you can set layer's transform:

    [CATransaction setDisableActions:YES]; // Disable animation
    layer1.transform = CATransform3DMakeRotation(alpha, 0, 0, 1); // Rotate layer