当用户在屏幕上捏住时,我需要不断更改MKCircle
的半径。因为它的radius
属性是只读的,所以我会连续删除并重新创建圆圈和渲染器,我相信这会导致闪烁"用户捏时的效果。当动画"动画时,它会不断出现/消失。在视觉上看起来非常糟糕,创造了一个糟透的UX。这是我的代码:
//this method may be called many times a second.
-(void)refreshRadius{ //called when user pinches after updating to correct radius.
if(radiusCircle){
[self.mapView removeOverlay:radiusCircle];
}
radiusCircle = [MKCircle circleWithCenterCoordinate:userCoordinates radius:radius];
[self.mapView addOverlay:radiusCircle level:MKOverlayLevelAboveLabels];
}
-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{
if(overlay == radiusCircle){
MKCircleRenderer *renderer = [[MKCircleRenderer alloc] initWithCircle:radiusCircle];
renderer.strokeColor = [UIColor colorWithWhite:1 alpha:0.5];
renderer.lineWidth = 0.8;
renderer.fillColor = [UIColor colorWithRed:0.3 green:0.36 blue:0.7 alpha:0.2];
return renderer;
}else{
return nil;
}
}
我怎样才能动画&#34;半径是否顺利?
答案 0 :(得分:0)
[radiusCircle setValue:@(radius) forKey:@"radius"];
[renderer invalidatePath];
radiusCircle
是我的MKCircle
个实例,renderer
是我的圆圈渲染器。它有效。