【问题标题】:iOS layer positioniOS层位置
【发布时间】:2014-12-03 07:00:16
【问题描述】:

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

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

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

【问题讨论】:

  • arcLayer.frame=self.circleView.bounds

标签: ios layer


【解决方案1】:

您在此行有问题:arcLayer.frame=self.circleView.frame;。将该行更改为:

CGRect frame = self.circleView.frame; 

frame.origin = CGPointZero;

arcLayer.frame=frame;

这将解决您的问题。您只是忘记将图层的原点设置为CGPointZero 或任何position。 祝你好运!

【讨论】:

    【解决方案2】:

    更简洁:

    arcLayer.frame = self.circleView.bounds;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多