0

enter image description here

Above image is my view before executing the following code.

@interface ViewController ()
@property (nonatomic, weak) IBOutlet UIView *layerView;
@end


@implementation ViewController
@synthesize layerView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_4);
    self.layerView.layer.affineTransform = transform;
}

... //  more code

enter image description here

And, above image is the view after executing the code. I want the snowman to be rotated to the same size. But, for some reason it's giving me a really small snowman... Can anyone notice the bug?

chanpkr
  • 895
  • 2
  • 10
  • 21
  • Are you using autolayout? [It's common for the autolayout constraints to interact badly with transformed views.](http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used/14105757#14105757) – Kurt Revis Mar 31 '14 at 04:17

1 Answers1

0

Layers use CATransform3D, not CGAffineTransform. The two are NOT interchangeable.

You should be getting a compiler warning for that code.

There are equivalent functions for manipulating CATransform3D. In this case you want CATransform3DMakeRotation. That method rotates around a 3D vector. You probably want to pass in 0 for x and y, and 1 for the z of your vector. That will make the layer perform a flat 2D rotation like your code would do with a CGAffineTransform applied to a view.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • You're correct about the regular `transform` property on CALayer, but there is also a method `setAffineTransform:` that takes a `CGAffineTransform`. – Kurt Revis Mar 31 '14 at 01:24
  • @KurtRevis, true enough, but that just confuses the issue at this point. – Duncan C Mar 31 '14 at 01:43
  • My point was, _that's the method his code is calling_. Therefore, it shouldn't cause a compiler warning. – Kurt Revis Mar 31 '14 at 02:15
  • @KurtRevis:Oh, you're right. My mistake. It sure looks like his transform is malformed from the attached image though. – Duncan C Mar 31 '14 at 11:19