I'm creating a custom on / off toggle switch for the iPhone (similar to the standard switch) and i'm at the point where I'm setting the mask of the slider, but calling [[myView layer] setMask:maskLayer]
sets the position of the mask layer relative to the layer it's masking, not relative to the container layer of the mask layer. For this particular scenario, the position of the mask layer needs to be set relative to it's containing layer because the toggle slider will move underneath the mask and the mask should stay stationary.
Without having to animate the mask AND the toggle slider component to achieve the desired effect, anyone know how to make this work? Here's what I've got so far:
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, nil, CGRectMake(0, 0, 13, 13));
CGPathAddEllipseInRect(path, nil, CGRectMake(30, 0, 13, 13));
CGPathAddRect(path, nil, CGRectMake(6, 0, 32, 13));
[maskLayer setPath:path];
[maskLayer setFillColor:[[UIColor greenColor] CGColor]];
[[self layer] addSublayer:maskLayer];
[maskLayer setPosition:CGPointMake(2, 2)];
[self addSubview:toggleView];
[[toggleView layer] setMask:maskLayer];