So I have an odd problem that I’m not quite sure why. To my understanding (and from the API for Xcode) it is noted that by default, the anchor point for a CALayer is 0.5 0.5 or the dead center of the CALayer before it. My question is, why does this not hold true for the CALayer the book had us create? For some reason, the defaulted anchor point was the upper left hand corner of the current CALayer. I had to change my anchor point to (-0.5, -0.5) to center my new Layer as shown below. Why is this? Why couldn’t I also use the position for the boxLayer? I’m already a little confused on differentiating between pixel locations (actual CGPoints) and percentage locations (such as 0.5 and 0.5 being %50 of the height and width). This just confused me lol.
myLayer = [[CALayer alloc]init];
[myLayer setBounds:CGRectMake(0.0, 0.0, [boxLayer bounds].size.width /2, [boxLayer bounds].size.height /2)];
//[myLayer setPosition:[boxLayer position]];
[myLayer setAnchorPoint:CGPointMake(-0.5, -0.5)]; //this centers the image at all times
UIImage *imageLayer = [UIImage imageNamed:@"TEALogoSprite.png"];
CGImageRef myImage = [imageLayer CGImage];
[myLayer setContents:(__bridge id)myImage];