我試圖使用疊加(MKOverlay
)在自由手上追蹤MKMapView
。無權在ios中繪製多段線疊加
當我們移動手指我去年與新座標的座標折線延長每一次,都正在擴展折線覆蓋整個覆蓋在設備閃爍(只是偶爾)時,除了做工精細,這樣我就可以,T跟蹤問題。
我試過的代碼在下面給出。
- (void)viewDidLoad
{
j=0;
coords1 = malloc(2* sizeof(CLLocationCoordinate2D));
coordinatearray=[[NSMutableArray alloc]init];
UIPanGestureRecognizer *GestureRecogonized = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gestureDetacted:)];
[self.myMapView addGestureRecognizer:GestureRecogonized];
}
- (void)gestureDetacted:(UIPanGestureRecognizer *)recognizer
{
if(UIGestureRecognizerStateBegan==recognizer.state)
{
CGPoint point = [recognizer locationInView:self.myMapView];
CLLocationCoordinate2D tapPoint = [self.myMapView convertPoint:point toCoordinateFromView:self.view];
CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:tapPoint.latitude longitude:tapPoint.longitude];
[coordinatearray addObject:curLocation];
}
coords1[0]=[[coordinatearray objectAtIndex:j] coordinate];
if(UIGestureRecognizerStateChanged==recognizer.state)
{
j++;
CGPoint point = [recognizer locationInView:self.myMapView];
CLLocationCoordinate2D tapPoint = [self.myMapView convertPoint:point toCoordinateFromView:self.view];
CLLocation *curLocation = [[CLLocation alloc] initWithLatitude:tapPoint.latitude longitude:tapPoint.longitude];
[coordinatearray addObject:curLocation];
coords1[1]=CLLocationCoordinate2DMake(tapPoint.latitude,tapPoint.longitude);
polyLine = [MKPolyline polylineWithCoordinates:coords1 count:2];
[self.myMapView addOverlay:polyLine];
}
}
在覆蓋委託
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
if([overlay isKindOfClass:[MKPolyline class]]){
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor orangeColor];
polylineView.lineWidth = 20;
polylineView.fillColor=[[UIColor orangeColor] colorWithAlphaComponent:.1];
return polylineView;
}
}
有誰能夠知道這是爲什麼閃爍或閃爍效果快到了,如何刪除它。
在此先感謝。
感謝您的回覆,唯一的問題是,我們通過自由手繪製折線時,所有先前添加的折線也會閃爍(閃爍),因此繪圖不會像連續一樣感覺。大部分時間工作正常,問題僅在保持地圖縮放水平在特定的水平,所以我不能追查真正的問題。我測試了設備中的代碼而不是模擬器。 – 2013-05-10 10:48:41
你說得對,我只注意到在特定的縮放級別,每次更新都會閃爍。但我相信我的方法應該會帶來更好的性能 – micantox 2013-05-10 10:55:13
謝謝,我永遠不會刪除我的代碼中添加的任何覆蓋圖 – 2013-05-10 11:05:37