我在一个UIView
命名的 containerView 上创建了一个跨越整个屏幕的容器视图。在这个视图CATransormLayer
上,必须添加一个具有以下尺寸的 UIView。
CATransformlayer : doubleSidedLayer
Height = containerView.frame.size.height
Width = containerView.frame.size.width
UIView : stripView
Height = containerView.frame.size.height
Width = 20;
它们的 x 位置由变量 positionX 指定。理论上两者都DoubleSidedLayer
必须stripView
重叠。但他们不是。
这是代码。
CGRect containerFrame =CGRectMake(0,0,self.view.frame.size.height,self.view.frame.size.width);
NSLog(@"container frame = %f %f %f %f",containerFrame.origin.x,containerFrame.origin.y,containerFrame.size.width,containerFrame.size.height);
UIView *containerView = [[UIView alloc]initWithFrame:containerFrame];
[containerView setBackgroundColor:[UIColor grayColor]];
float positionX = containerFrame.size.width/4;//This is the position where the stripView and doubleSidedLayer must be placed
//Configuration of CATransformLayer.
CGRect doubleLayerFrame = CGRectMake(positionX,0,containerFrame.size.width/2,containerFrame.size.height);
CATransformLayer *doubleSidedLayer = [CATransformLayer layer];
[doubleSidedLayer setFrame:doubleLayerFrame];
NSLog(@"DoubleSidedLayer frame = %f %f %f %f",doubleSidedLayer.frame.origin.x,doubleSidedLayer.frame.origin.y,doubleSidedLayer.frame.size.width,doubleSidedLayer.frame.size.height);
NSLog(@"DoubleSidedLayer bounds = %f %f %f %f",doubleSidedLayer.bounds.origin.x,doubleSidedLayer.bounds.origin.y,doubleSidedLayer.bounds.size.width,doubleSidedLayer.bounds.size.height);
NSLog(@"Anchor Points = %f %f",doubleSidedLayer.anchorPoint.x, doubleSidedLayer.anchorPoint.y);
NSLog(@"position = %f %f",doubleSidedLayer.position.x,doubleSidedLayer.position.y);
//Configuring top layer
CALayer *topLayer = [[CALayer alloc]init];
[topLayer setFrame:doubleLayerFrame];
[topLayer setContents:(id)[UIImage imageNamed:@"1.png"].CGImage];
[topLayer setZPosition:2];
[topLayer setDoubleSided:NO];
//Adding the layers
[doubleSidedLayer addSublayer:topLayer];
[containerView.layer addSublayer:doubleSidedLayer];
//Adding the stripView
UIView *stripView = [[UIView alloc]initWithFrame:CGRectMake(positionX, 0, 20,containerView.frame.size.height)];
[stripView setBackgroundColor:[UIColor cyanColor]];
[containerView addSubview:stripView];
NSLog(@"Strip frame = %f %f %f %f",stripView.frame.origin.x,stripView.frame.origin.y,stripView.frame.size.width,stripView.frame.size.height);
//Adding the containerView to the main view
[self.view addSubview:containerView];
从日志语句中可以看到 doubleSidedLayer 和 stripView 的帧。
doubleSidedLayer frame = 120.000000 0.000000 240.000000 300.000000
strip frame = 120.000000 0.000000 20.000000 300.000000
但两者不重叠。这是屏幕截图。
注意:我正在横向工作。