完全删除UIBezierPath& CAShapeLayer绘制的项目

时间:2014-12-03 15:49:41

标签: ios objective-c drawing uibezierpath cashapelayer

在纵向模式下(第一次绘图)

enter image description here

旋转到横向后,为什么旧​​的形状:

enter image description here

我正在使用UIBezierPath& CAShapeLayer画圆圈&自定义UIView图层中的行。问题在于能够吸引新的圈子和新的圈子。设备旋转后成功的线条,我无法删除旧的绘制形状。 在设备旋转后绘制的新形状是完美的,我只需要从屏幕上移除那些粘在屏幕上的旧形状。 图片附件。

3 个答案:

答案 0 :(得分:10)

您可以删除之前的CAShapeLayer(使用removeFromSuperlayer)或替换之前path的{​​{1}}。您似乎是在不删除旧图层的情况下添加新图层,但当然没有源代码就无法分辨。

答案 1 :(得分:3)

AAH! 找到了解决方案 使用rootView.layer.sublayers = nil删除了所有早期形状

答案 2 :(得分:1)

对我

Dataset <-
structure(list(specie = structure(c(26L, 25L, 24L, 23L, 22L, 
21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 
8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L, 26L, 25L, 24L, 23L, 22L, 21L, 
20L, 19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 
7L, 6L, 5L, 4L, 3L, 2L, 1L, 26L, 25L, 24L, 23L, 22L, 21L, 20L, 
19L, 18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 
6L, 5L, 4L, 3L, 2L, 1L, 26L, 25L, 24L, 23L, 22L, 21L, 20L, 19L, 
18L, 17L, 16L, 15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 7L, 6L, 
5L, 4L, 3L, 2L, 1L), .Label = c("ar", "br", "cr", "dr", "er", 
"fr", "Gr", "hr", "Ir", "jr", "kr", "lr", "mr", "nr", "or", "pr", 
"qr", "rr", "sr", "tr", "ur", "vr", "wr", "xr", "yr", "zr"), class = "factor"), 
    momento = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L, 4L), .Label = c("M1", "M2", "M3", "M4"), class = "factor"), 
    M1_sava = c(1, 0.86, 1, 1, 1, 0.74, 0.39, 0.83, 0.83, 0, 
    0.7, 0.11, 1, 0, 0, 0, 0, 0.83, 0, 0, 0, 0, 0, 0.04, 0, 0, 
    0.33, 0.86, 0.39, 0.02, 0.07, 0.02, 0.87, 0.06, 0.63, 0.33, 
    0.91, 0.67, 0.18, 0.08, 0, 0, 0, 0, 0.08, 0, 0.04, 0, 0, 
    0, 0, 0, 0.04, 0.32, 0.02, 0, 0, 0, 0.96, 0.06, 0.18, 0.33, 
    0.63, 1, 0, 0.94, 0.17, 0, 0.41, 0.04, 0.44, 0.17, 0.02, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.89, 0, 0.03, 0.22, 0.41, 
    0.46, 0, 0.81, 0.39, 0.7, 0.7, 0, 0.87, 0.91, 0.33, 0.37, 
    0.24, 0.15, 0, 0)), class = "data.frame", row.names = c(NA, 
-104L))

引发了内存异常,但是由于我只需要删除CAShapeLayer对象,因此以下代码对我有用:

rootView.layer.sublayers = nil