gpt4 book ai didi

iphone - MKMapView -> 为我的位置显示一个按钮

转载 作者:可可西里 更新时间:2023-11-01 04:42:55 25 4
gpt4 key购买 nike

我有一个使用这些源代码行实现的MKMapView(我的位置是一个蓝色的子弹,另一个是紫色的别针):

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
if (annotation == mapViewLocal.userLocation) {
mapViewLocal.userLocation.title = @"Test";
[mapViewLocal setRegion:MKCoordinateRegionMakeWithDistance(mapViewLocal.userLocation.coordinate, 1000, 1000) animated:YES];
return nil;
}

MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.animatesDrop = NO;
pinView.canShowCallout = YES;
} else {
pinView.annotation = annotation;
}
return pinView;
}

紫色图钉有详细信息披露按钮,但我的注释没有。如何设置这样的按钮?

这就是我可以在按下按钮时做某事的方法:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

我如何区分我的位置和所有其他人的位置,因为我需要不同的处理方式。是否有另一个代表,或者我是否必须制作某种 if 子句?

最佳答案

在你的 didUpdateToLocation 中写一些像

AddressAnnotation   *myAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation];
myAnnotation.title = @"You are here";
[self.mapView addAnnotation:myAnnotation];

然后

类似的东西

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = @"annotationIdentifier";

NSString *titlestr = annotation.title;

MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
if (!pinView)
{
// if an existing pin view was not available, create one
// MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
//initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
if([titlestr isEqualToString:@"You are here"])
{
customPinView.pinColor = MKPinAnnotationColorGreen;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
}
else{
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.selected = TRUE;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(ShowStoreDetail:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
}
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;

return customPinView;
}
else
{
pinView.annotation = annotation;



if([titlestr isEqualToString:@"You are here"])
{
customPinView.pinColor = MKPinAnnotationColorPurple;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
}
else{
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.selected = TRUE;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(ShowStoreDetail:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
}


}
return pinView;

return nil;
}

关于iphone - MKMapView -> 为我的位置显示一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2066362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com