【发布时间】:2011-06-23 05:20:53
【问题描述】:
我有一个在地图上放置注释的 mapkit 应用,当你按下它们时,它会显示带有 title 属性的标注。
这工作正常,但用户无法关闭它们。他们保持打开状态,直到他们点击另一个注释。我不能让用户可以在地图上点击 elsehwere(或再次点击注释)来关闭它吗?
我感觉这是默认设置,所以也许我正在做的事情是把它塞进去?我有一个手势识别器,我用它来检测一些地图点击
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
[self.mapView addGestureRecognizer: tap];
触发这个:
- (void)handleTap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
CGPoint tapPoint = [sender locationInView:sender.view.superview];
CLLocationCoordinate2D coordinate = [self.mapView convertPoint: tapPoint toCoordinateFromView: self.mapView];
if (pitStopMode && !pitStopMade){
pitStopMade = YES;
InfoAnnotation *annotation = [[InfoAnnotation alloc]
initNewPitstopWithCoordinate:coordinate];
NSLog(@" Created Pit Stop");
annotation.draggable = NO;
//place it on the map
[self.mapView addAnnotation: annotation];
self.instructionLabel.text = @"Tap button again to remove";
annotation.creatorId = self.localUser.deviceId;
//send it to the server
[annotation updateLocationWithServerForConvoy: self.convoyCode];
[annotation release];
}
if (hazardMode && !hazardMade){
hazardMade = YES;
InfoAnnotation *annotation = [[InfoAnnotation alloc]
initNewHazardWithCoordinate:coordinate];
NSLog(@" Created Hazard");
annotation.draggable = NO;
//place it on the map
[self.mapView addAnnotation: annotation];
self.instructionLabel.text = @"Tap button again to remove";
annotation.creatorId = self.localUser.deviceId;
//send it to the server
[annotation updateLocationWithServerForConvoy: self.convoyCode];
[annotation release];
}
}
}
我还需要做什么才能让这些点击进入地图视图吗?拖动并点击注释可以正常工作,所以我不确定这是否是导致它的原因?
是否有我遗漏的选项,或者我必须尝试手动实现它?
【问题讨论】:
标签: objective-c ios mapkit