Ich möchte ein Unendlichkeitssymbol zeichnen und auf diesem Pfad muss ich einen gefüllten Kreis bewegen, um den ganzen Weg zu bedecken. Und es sollte customize-fähig sein, wie für einige Wert sollte es auf der linken Seite bleiben und für etwas Wert wird es auf eine andere Seite gehen. Is this possible first of all ?
Wie zeichnet man die Unendlichkeit und bewegt den Kreis auf diesem Weg?
Im Moment bin ich in der Lage, einen Kreis zu zeichnen, und ich bin in der Lage Kreis auf diesem Weg zu bewegen, dies mit:
let circlePath = UIBezierPath(arcCenter: CGPoint(x:self.view.frame.midX, y:self.view.frame.midY), radius: self.view.frame.size.width/3, startAngle: 0, endAngle:CGFloat(Double.pi)*2, clockwise: true)
circlePathSize = circlePath.bounds.size
// circleLayer is only used to locate the circle animation path
circleLayer.path = circlePath.cgPath
circleLayer.strokeColor = UIColor.white.cgColor
circleLayer.shadowColor = UIColor.darkGray.cgColor
circleLayer.shadowOpacity = 7.0
circleLayer.shadowRadius = 2.0
circleLayer.shadowOffset = CGSize(width: -1, height: 0)
circleLayer.lineWidth = 3.0
circleLayer.fillColor = UIColor.clear.cgColor
self.view.layer.addSublayer(circleLayer)
let animation = CAKeyframeAnimation(keyPath: "position");
animation.duration = 5.0
animation.repeatCount = MAXFLOAT
animation.path = circlePath.cgPath
//whatever the value of origin for squareView will not affect the animation
squareView.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
squareView.layer.cornerRadius = 10
squareView.layer.shadowColor = UIColor.darkGray.cgColor
squareView.layer.shadowOpacity = 7.0
squareView.layer.shadowRadius = 3.0
squareView.layer.shadowOffset = CGSize(width: 2, height: 0)
squareView.backgroundColor = UIColor.white
self.view.addSubview(squareView)
// You can also pass any unique string value for key
squareView.layer.add(animation, forKey: nil)
Und ich bin in der Lage Sinuskurve zeichnen auch diese mit:
let origin = CGPoint(x: width * (1 - graphWidth)/2, y: height * 0.50)
let path = UIBezierPath()
path.move(to: origin)
for angle in stride(from: 5.0, through: 360.0, by: 5.0) {
let x = origin.x + CGFloat(angle/360.0) * width * graphWidth
let y = origin.y - CGFloat(sin(angle/180.0 * Double.pi)) * height * amplitude
path.addLine(to: CGPoint(x: x, y: y))
}
UIColor.white.setStroke()
path.stroke()
Aber ich bin nicht in der Lage, sie zu mischen, um zu bekommen, was ich begehre. Jede Hilfe wäre willkommen. Vielen Dank.
Warum ist der Weg zum framekeyanimation gegeben ein Kreis ist, anstelle des Sinuskurvenpfades, den Sie bereits erstellt haben? –
Ja, dass ich weiß, aber es ist nicht unendlich Symbol. Zuerst möchte ich das Unendlichkeitssymbol zeichnen. Wie zu dem? @ PuneetSharma –