0

I am trying to create an MKCircle around a dropped pin and have the radius adjustable with a UISlider.

In my slider method that calls when the user changes the value of the slider. I attempt to simply reference the circle and say:

circle.radius = slider.value;

However I receive the error: "Assignment to readonly property."

Thank You!

Eli Whittle
  • 1,084
  • 1
  • 15
  • 19

1 Answers1

-1

I think you can use an IBAction, like this

-(IBAction)sliderValueChange:(UISlider *)sender {
float value = [sender.value floatValue];
circle = nil; 
CLLocationCoordinate2D center; //Add your CLLocationCoordinate2D
circle = [MKCircle circleWithCenterCoordinate:center radius:value];
[self.mapView addOverlay:circle];
}
Vincent
  • 41
  • 1
  • 6
  • This doesn't work as posted. This: float value = [sender.value floatValue];... results in an error. However I was able to get the slider to adjust the radius of newly placed circles with the slider by basically storing the value of the radius with a float. However I am still having trouble dynamically updating the radius as I slide. – Eli Whittle Jul 16 '14 at 01:57
  • Why not? Can you tell me what's happening, that way I will be more than happy to help – Vincent Jul 16 '14 at 02:03
  • So I did this... - (IBAction)slide:(UISlider *)sender { [mapView removeOverlay:cir]; rad = slider.value; cir = [MKCircle circleWithCenterCoordinate:circleCenter radius:rad]; [mapView addOverlay:cir]; [circleArray addObject:cir]; } cir is an MKCircle that can also be added by pressing a button. circleCenter is just a variable that finds the center of the screen. It makes a new circle with the right sized rad but im making a new circle each time so the screen is pretty laggy/sketchy. – Eli Whittle Jul 16 '14 at 02:12
  • I cant just say cir.radius = slider.value I get the error "Assignment to readonly property." Do you know anyway around this. The var cir represents an MKCircle. – Eli Whittle Jul 17 '14 at 04:14
  • No you cant, you can dealloc the MKCircle and reallocate it programmatically like this circle = nil; CLLocationCoordinate2D center; //Add your CLLocationCoordinate2D circle = [MKCircle circleWithCenterCoordinate:center radius:value]; – Vincent Jul 17 '14 at 04:58
  • Okay, thanks. That works but its really glitchy this way. Basically every time the sliders value is changed the old circle is eliminated from the view and the memory and a new one is instantiated. Is there a way to simply just change the radius of the originally instantiated circle and update it on the map when the slider is called? Clearing & making a new one every time doesn't look very smooth. – Eli Whittle Jul 17 '14 at 17:25