Here's the solution: you need to add the broadcast to the superlayer, and then make up for it by adjusting the position of the sublevel. I successfully used the following code snippet, just creating an empty โSingle View Applicationโ Xcode project and running it on the iPad simulator:
- (void)viewDidLoad { [super viewDidLoad]; for (int i = 0; i < 6; i++) { CALayer *parent = [CALayer layer]; parent.frame = CGRectMake(0, 0, 100, 100); parent.position = CGPointMake(70 + 120*i, 70); parent.backgroundColor = [[UIColor greenColor] CGColor]; [self.view.layer addSublayer:parent]; float width = self.view.frame.size.width/2.0; float offset = (width - parent.position.x); CALayer *layer = [CALayer layer]; layer.frame = CGRectMake(0, 0, 40, 40); layer.position = CGPointMake(-offset + 50, 60); layer.backgroundColor = [[UIColor redColor] CGColor]; layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 1, 0); CATransform3D tr = CATransform3DMakeTranslation(offset, 0, 0); CATransform3D t = CATransform3DIdentity ; t.m34 = -4.0f/2000.0f ; parent.sublayerTransform = CATransform3DConcat(t, tr); [parent addSublayer:layer]; } }
source share