Question

I have a problem with the resolution of my CALayers that looks blurry after zooming in. I know that there are plenty of posts about it but, after reading lots of them I couldn't find out a solution yet and I'm confused about it.

SITUATION: The App have a UIViewController with a UIView. Under this UIView there is a CALayer, with a CGPath defining its shape, added as [[self layer] addSublayer:myCALayer]. If the user taps on a button, there are a certain number of other CALayers are added as a sublayers to the main CALayer (myLayer -> [myLayer addSublayer:Layer]). The difference between my case and the posts found on the web are that I haven't UIImages, UIImageViews, etc, only plain and basic CALayers with a certain backgroundColor. There is no UIScrollViews only UIGestureRecognizers (tap, doubleTap, Pinch and Pan). All this stuff works good.

PROBLEM: When I zoom in the CALayers become blurry.

Here is an image of the problem:

And here is my code:

This the main CALayer defined on the UIView:

- (id)initWithFrame:(CGRect)frame
{
    [super initWithFrame:frame]; 

    (…)

    perfil = [[CALayer alloc] init];
    perfilDelegate = [[perfilLayerDelegate alloc] init];
    [perfil setDelegate:perfilDelegate];
    [perfil setBounds:CGRectMake(0, 0, wideP, heigthP/2)];
    [perfil setPosition:CGPointMake(wideP/2, heigthP*3/4)];

    [perfil setShouldRasterize:TRUE];
    [perfil setRasterizationScale:[[perfil valueForKeyPath:@"transform.scale"] floatValue]];

    [[self layer] addSublayer:perfil];

    (…)
}

And these are the other subLayers defined on the UIView when the user tap a button:

for (int i=0; i<[numLayers count]; i++)
{
    CALayer *Layer = [[CALayer alloc] init];

    punt = [[numLayers objectAtIndex:i] CGPointValue];

    [Layer setBounds:CGRectMake(0.0, 0.0, wideL, heigthL)]; 

    [Layer setBorderWidth:2.0];
    UIColor *reddish = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3];
    [Layer setBorderColor:[reddish CGColor]];
    [Layer setPosition:[[numLayers objectAtIndex:i] CGPointValue]];
    [Layer setCornerRadius:[Layer bounds].size.width/2];

    reddish = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.2];
    CGColorRef cgReddish = [reddish CGColor];
    [Layer setBackgroundColor:cgReddish];

    [Layer setShouldRasterize:YES];
    [Layer setRasterizationScale:[[perfil valueForKeyPath:@"transform.scale"] floatValue]];

    [perfil addSublayer:Layer];

    [Layer release];
}

Any hint would be very appreciated. Thank you.

Was it helpful?

Solution

After optimizing my code, one of the improvements I've done is to change the "perfil" CALayer to a CAShapelayer. I suppose I had something wrong working with the CALayer but now works perfectly well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top