2016-12-15 7 views
0

나는 타임 라인보기에서 작업 중입니다. 내 아이콘의 중앙에 선을 그려서 채우기 색으로 원을 그립니다. 그러나 문제는 내가 원을 그릴 때 항상 아이콘 상단에 있다는 것입니다. 이제 아이콘이 표시되지 않습니다. 나는 레이어의 zposition을 시도했다. 여기에 내가 신속한 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를 사용하면 위에 추가 된 다른 모든 항목을 덮을 새 레이어가 추가됩니다. 당신이 당신의 아이콘에있는 계층 알고있는 경우

, 당신은 대신 또는

당신은 스토리 보드와 장소에있는 아이콘의 정확한 프레임 다른 UIView의를 만들 수 있습니다 아이콘 아래에 배치하기에 :) insertSublayer을 (사용할 수 있습니다 계층 구조가 더 낮아서 끌기가 끝나면 끝납니다.