Ben H
Ben H

Reputation: 3915

Why does this drawing code work on some iPads running iOS 8.1, but not others?

i've run into a bizarre problem where my code works on some iPad models, but not others, even when they are running the same version of iOS. this simple code to draw a white circle works on my iPad 4 running iOS 8.1.1, but not on my iPad Mini Retina running 8.1.1. this is even reproducible in the simulators. it works when running on an "iPad Retina 8.1" or "iPad 2 8.1" simulator, but not an "iPad Air 8.1". when it doesn't work, it doesn't draw a small white circle. the view is blank. why is this happening?

@implementation MyUIViewSubclass
{
    CAShapeLayer* animationLayer;
    CGMutablePathRef smallCircle;
}

- (id) initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder])
    {
        smallCircle = CGPathCreateMutable();
        CGPathAddArc(smallCircle, NULL, self.bounds.size.width / 2, self.bounds.size.height / 2, 32, (CGFloat)M_PI, -(CGFloat)M_PI, NO);

        animationLayer = [CAShapeLayer layer];
        animationLayer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
        animationLayer.lineWidth = 1;
        animationLayer.strokeColor = [[UIColor whiteColor] CGColor];
        animationLayer.fillColor = [[UIColor clearColor] CGColor];
        animationLayer.path = smallCircle;

        [self.layer addSublayer:animationLayer];
    }
    return self;
}

@end

Upvotes: 0

Views: 59

Answers (1)

Ben H
Ben H

Reputation: 3915

figured this out while i was writing the question. it didn't work on 64bit devices. when i changed the CGFloat to float, it worked. CGFloat is defined differently on 32 vs 64 bit platforms.

Upvotes: 1

Related Questions