-(void) bringSublayerToFront:(CALayer*)layer
{[layer removeFromSuperlayer];[self insertSublayer:layer atIndex:[self.sublayers count]-1];}-(void) sendSublayerToBack:(CALayer*)layer
{[layer removeFromSuperlayer];[self insertSublayer:layer atIndex:0];}
Note: if you don't use ARC, you may wish to add [layer retain]
at top and [layer release]
at bottom of both functions to make sure layer
is not accidentally destructed in a case it has retain count = 1.