gpt4 book ai didi

ios - 触摸时如何检测另一个 MKAnnotaion 引脚

转载 作者:行者123 更新时间:2023-11-29 01:09:09 26 4
gpt4 key购买 nike

我在 map(place1,place2) 中有多个注释图钉

我希望用户触摸引脚转到新的Viewcontroller以获取地点描述

它有功能检测引脚以触摸它以转到descriptionViewController吗?

这是我的代码

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


MKCoordinateRegion place1 = { {0.0, 0.0} , {0.0, 0.0} };
place1.center.latitude = 34.7037755;
place1.center.longitude = 137.7345882;
place1.span.longitudeDelta = 0.02f;
place1.span.latitudeDelta = 0.02f;
[mapView setRegion:place1 animated:YES];

Newclass *ann1 = [[Newclass alloc] init];
ann1.title = @"Place1";
ann1.subtitle = @"subtitle";
ann1.coordinate = place1.center;
[mapView addAnnotation: ann1];

MKCoordinateRegion place2 = { {0.0, 0.0} , {0.0, 0.0} };
place2.center.latitude = 34.7024461;
place2.center.longitude = 137.7297572;
place2.span.longitudeDelta = 0.02f;
place2.span.latitudeDelta = 0.02f;
[mapView setRegion:place2 animated:YES];

Newclass *ann2 = [[Newclass alloc] init];
ann2.title = @"place2";
ann2.subtitle = @"subtitle";
ann2.coordinate = place2.center;
[mapView addAnnotation:ann2];


}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
MKPinAnnotationView *myPin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"current"];
myPin.pinColor = MKPinAnnotationColorGreen;

UIButton *advertButtom = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[advertButtom addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];

myPin.rightCalloutAccessoryView = advertButtom;
myPin.draggable =NO;
myPin.animatesDrop =true;
myPin.canShowCallout=YES;

return myPin;

}

-(void)button:(id)sender{
NSUserDefaults *defults = [NSUserDefaults standardUserDefaults];
UIStoryboard *storyboard = [self storyboard];
descriptionViewController *description = [storyboard instantiateViewControllerWithIdentifier:@"des"];
[self presentModalViewController:description animated:YES];


NSLog(@"touched");
NSLog(@"data %@");
}

最佳答案

你需要使用mapView方法

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
NSUserDefaults *defults = [NSUserDefaults standardUserDefaults];
UIStoryboard *storyboard = [self storyboard];
descriptionViewController *description = [storyboard instantiateViewControllerWithIdentifier:@"des"];
[self presentModalViewController:description animated:YES];


NSLog(@"touched");
NSLog(@"data %@");
}

关于ios - 触摸时如何检测另一个 MKAnnotaion 引脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35979952/

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