iOS图层位置

标签 ios layer

我想在 View 上绘制一个图层。为此,我编写了这段代码。

arcLayer=[CAShapeLayer layer];
arcLayer.frame=self.circleView.frame;
arcLayer.backgroundColor = [UIColor purpleColor].CGColor;
[self.circleView.layer addSublayer:arcLayer];

但是这个层的位置在 View 上并不准确,如下图所示。绿色的是circleView,紫色的是arc层。

enter image description here

最佳答案

你在这行有问题: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/

相关文章:

iphone - 如何以编程方式绘制边框并在 UIImageview 周围的单词后将其删除?

ios - iPhone 应用程序在使用 SIGABRT 的 AppDelegate 中启动时崩溃

javascript - 在 Fabric.js 中分层 Canvas 对象

canvas - Kinetic.JS - 无法更改图层的 z-index 顺序?

ios - 如何接收异步任务完成的通知

ios - MaterializeCss 不适用于 ios

ios - objective-c plist 尾随零

Android - 更改由 onClick 事件触发的 LayerDrawable 项目的 alpha 值

javascript - 具有非地理图像的传单基础层控制?

python - 如何在Tensorflow 2.x Keras自定义层中使用多个输入?