Take the 2-minute tour ×

I have developed an animated Pie Chart, in which when a user clicks on a Pie Chart slice, it comes out of the chart. Currently, I am drawing each slice of the Pie on a different CGLayer. When the user taps on a slice I pick the color of that particular pixel and match it with the RGB code (hard-coded) which pulls out the corresponding layer.

I don't want to use any third-party charting library like core plot.

Is there a way to make each layer an individual graphic entity, so that a touch on that object can be detected?


share|improve this question
add comment

3 Answers

Can't you just use the X,Y coordinate of the touch to calculate the angle to the center of the pie chart along with the distance?

If the distance is lesser than the radius then use the angle to figure out which chart was tapped on.

share|improve this answer
add comment

If you are using CG then you can test if a point is within a path.

Checkout CGPathContainsPoint here.

share|improve this answer
add comment

I used CAShapeLayer to represent individual pie slices. CAShapeLayer instances have a path property which you can use to test if a point is within that path.

Just detect the touch point on the parent UIView and then iterate over all your pie slices and use the CGPathContainsPoint function to test if the point is within that pie slice.

share|improve this answer
add comment

Your Answer


