无法设置CALayer帧

时间:2012-03-27 10:04:16

标签: iphone ios xcode calayer subview

我正在尝试在下面的代码中设置CALayer的框架

CGRect VFrame;
VFrame = CGRectMake(self.viewNo2.frame.origin.x, self.viewNo2.frame.origin.y, self.viewNo2.frame.size.width, self.viewNo2.frame.size.height);

self.customLayer = [CALayer layer];
self.customLayer.frame = VFrame;
self.customLayer.contentsGravity = kCAGravityResizeAspectFill;
[self.view.layer addSublayer:self.customLayer];

出于某种原因,图层会在此帧周围的某处出现,但不会像我想要声明的帧那样。

有谁知道这是什么问题?

1 个答案:

答案 0 :(得分:0)

//try this,simply assign frame to viewNo2 frame
self.viewNo2.frame.size.width, self.viewNo2.frame.size.height);
self.customLayer = [CALayer layer];
self.customLayer.frame = viewNo2.frame;
self.customLayer.contentsGravity = kCAGravityResizeAspectFill;
[self.view.layer addSublayer:self.customLayer];