2016-12-15 82 views
0

我正在研究时间轴视图。我在我的图标中心绘制了一条线,并用填充颜色绘制了一个圆。但问题是,当我绘制圆时,它总是在图标的顶部。现在图标没有显示。我尝试了图层的位置。以下是我试过快速定位uiview图层

override func draw(_ rect: CGRect) { 
      if let anchor = anchorView(){ 
       let centreRelativeToTableView = anchor.superview!.convert(anchor.center, to: self) 
       // print("Anchor x origin : \(anchor.frame.size.origin.x)") 
       timelinePoint.position = CGPoint(x: centreRelativeToTableView.x , y: centreRelativeToTableView.y/2) 
       timeline.start = CGPoint(x: centreRelativeToTableView.x , y: 0) 
       timeline.middle = CGPoint(x: timeline.start.x, y: anchor.frame.origin.y) 
       timeline.end = CGPoint(x: timeline.start.x, y: self.bounds.size.height) 
       timeline.draw(view: self.contentView) 




       let circlePath = UIBezierPath(arcCenter: CGPoint(x: anchor.center.x,y: anchor.center.y - 20), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true) 

       let shapeLayer = CAShapeLayer() 
       shapeLayer.path = circlePath.cgPath 

       //change the fill color 
       shapeLayer.fillColor = UIColor.randomFlat.cgColor 
       // shapeLayer.fillColor = UIColor.clear.cgColor 

       //you can change the stroke color 
       shapeLayer.strokeColor = UIColor.white.cgColor 
       //you can change the line width 
       shapeLayer.lineWidth = 5 
       shapeLayer.zPosition = 0 
       anchor.alpha = 1 
       //Set Anchor Z position 
        anchor.layer.zPosition = 2 
       shapeLayer.zPosition = 1 

       anchor.layer.addSublayer(shapeLayer) 


       // Setting icon to layer 
       /*let imageLayer = CALayer() 
       imageLayer.contents = newImage 
       anchor.layer.addSublayer(imageLayer)*/ 
       // timelinePoint.draw(view: self.contentView) 
      }else{ 
       print("this should not happen") 
      } 


} 

ss1 ------- s2

我想画我的图标与白色的色调在圆的上方。请帮助我

回答

0

使用addSublayer将在顶部添加新图层,它将覆盖之前添加的所有内容。

如果你知道你的图标在哪一层,你可以改用insertSublayer(在:)将它放在图标下

另外,您可以创建另一个UIView的与图标的故事板和地点的确切框架它在层次结构中较低,因此无论您的绘制结果如何。