我想在 View 上绘制一个图层。为此,我编写了这段代码。
arcLayer=[CAShapeLayer layer];
arcLayer.frame=self.circleView.frame;
arcLayer.backgroundColor = [UIColor purpleColor].CGColor;
[self.circleView.layer addSublayer:arcLayer];
但是这个层的位置在 View 上并不准确,如下图所示。绿色的是circleView,紫色的是arc层。
最佳答案
你在这行有问题:arcLayer.frame=self.circleView.frame;
。将该行更改为:
CGRect frame = self.circleView.frame;
frame.origin = CGPointZero;
arcLayer.frame=frame;
这将解决您的问题。您只是忘记将层的原点设置为 CGPointZero
或任何 position
。
祝你好运!
关于iOS图层位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27265538/