2016-12-15 3 views
0

Je travaille sur une vue chronologique. Je trace une ligne au centre de mon icône et dessine un cercle avec la couleur de remplissage. Mais le problème est que lorsque je dessine le cercle, il est toujours en haut de l'icône. Maintenant, l'icône ne s'affiche pas. J'ai essayé zposition des calques. Voici ce que j'ai essayéPositionnement des couches de uiview dans swift

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

Je veux dessiner mon icône avec une teinte blanche sur le dessus du cercle. Aidez-moi s'il vous plaît

Répondre

0

L'utilisation de addSublayer ajoutera la nouvelle couche sur le dessus, qui couvrira tout le reste ajouté auparavant.

Si vous savez quelle couche l'icône est à, vous pouvez utiliser à la place insertSublayer (à :) de le placer sous l'icône

Sinon, vous pouvez créer un autre UIView avec l'image exacte de l'icône en story-board et lieu il est plus bas dans la hiérarchie donc tout ce que votre tirage finit sous.