0

My app uses a lot of programatically positioned CALayers and I use image asset catalogues for all my images. Last night, I upgraded to Xcode 6 to start preparing the app for iPhone 6. However, when I checked in the simulator none of the CALayers seem to be positioned correctly even in the iPad Retina device. So, I'm wondering, does someone have an idea where the problem might be coming from?

I'm doing this sort of thing to position the layers by the way.

-(CALayer *)loadLayer:(CGFloat)x :(CGFloat)y :(CGFloat)width :(CGFloat)height :(NSString *)layerName
{

CALayer *layerToAdd = [[CALayer alloc] init];
[layerToAdd setBounds:CGRectMake(0, 0, width, height)];
[layerToAdd setPosition:CGPointMake(x + width/2, y + height/2)];
layerToAdd.name = layerName;
[self.view.layer addSublayer:layerToAdd];
return layerToAdd;

}

Many thanks.

pingin
  • 482
  • 1
  • 6
  • 19
  • Do you mean Xcode 6 or iOS 8? – trojanfoe Sep 22 '14 at 11:49
  • I mean Xcode 6. My app seems to work fine on iOS 8. So I'm thinking that the problem must be with the way my project is being built in Xcode 6. On the simulator, I'm viewing it on iOS 8 but the app should support iOS 7 iOS 6.I should also say, I've only tried it on the Simulator so far. – pingin Sep 22 '14 at 12:20

1 Answers1

0

I think I've traced the problem to the width and height properties having been switched to something more intuitive now. My app runs in landscape mode only and looking at my code, it seems that prior to Xcode 6 (or earlier?) the width was the physical width of the device in portrait mode — so even it was running in landscape mode, 'width' actually referred to height. So I've been able to fix most of the problems with my app by simply changing these two lines:

viewWidthInPoints =  bounds.size.height;
viewHeightInPoints =  bounds.size.width;

to

viewWidthInPoints =  bounds.size.width;
viewHeightInPoints =  bounds.size.height;

Just answering it here in case someone runs into a similar problem.

More details can be found here: Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?

Community
  • 1
  • 1
pingin
  • 482
  • 1
  • 6
  • 19