0

I have created a circle and would like to role another object around this circle. They are both with a UIView.Like a compass point rotating around. I think I understand the process but it doesn't work.

@IBOutlet weak var compassArea: UIView!

var compassRing = CAShapeLayer()
var compassRingPath = UIBezierPath()
var compassPoint = UIView()

        //compassRingPath.moveToPoint(CGPoint(x: CGFloat(compassArea.frame.width/2), y: CGFloat(compassArea.frame.height/2)))
    compassRingPath.addArcWithCenter(CGPoint(x: CGFloat(compassArea.frame.width/2), y: CGFloat(compassArea.frame.height/2)), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

    compassRing.path = compassRingPath.CGPath
    compassRing.name = "highlight"
    compassRing.lineDashPattern = [1.0,2.0]
    compassRing.fillColor = UIColor.clearColor().CGColor
    compassRing.strokeColor = UIColor.whiteColor().colorWithAlphaComponent(0.75).CGColor
    compassRing.lineWidth = 10.0

    compassArea.layer.addSublayer(compassRing)

    compassPoint.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    compassPoint.frame = CGRect(x: CGFloat(compassArea.frame.width/2)-5, y: CGFloat(compassArea.frame.height/2)-105, width: 10, height: 10)

    compassPoint.layer.cornerRadius = 5
    compassPoint.backgroundColor = UIColor.redColor()
    self.compassArea.addSubview(compassPoint)

    dispatch_async(dispatch_get_main_queue(), {

        UIView.animateWithDuration(10, delay: 0.5, options: .CurveLinear, animations: {

            self.compassPoint.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
            //self.compassPoint.transform = CGAffineTransformRotate(CGAffineTransformIdentity, CGFloat(270.0/180*M_PI))

            }, completion: { finished in
                //Do something
        })

    })

This draws okay, but I can not make the compassPoint move around the compassRing.

Cœur
  • 37,241
  • 25
  • 195
  • 267
duck1970
  • 127
  • 10
  • Pretty well covered here, I think: http://stackoverflow.com/questions/28399892/how-to-create-a-caanimation-effect-like-moon-rotates-around-the-earth-and-rotate – matt May 31 '16 at 00:30
  • Okay cool, thanks got that. But how do I move around a segment of the curve (e.g. 90 to 180 degrees)? – duck1970 May 31 '16 at 20:00

0 Answers0