gpt4 book ai didi

uimap 标注 subview 上的 IOS 事件单击

转载 作者:行者123 更新时间:2023-11-29 03:04:24 24 4
gpt4 key购买 nike

我正在 IOS 上创建一个 map ,并在每个注释点击上添加一个自定义 subview ,如下所示:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

//load pin callout
nearbyMapCallout *calloutView = [[nearbyMapCallout alloc]init];
calloutView = (nearbyMapCallout *)[[[NSBundle mainBundle] loadNibNamed:@"nearbyMapCallout" owner:self options:nil] objectAtIndex:0];

CGRect calloutViewFrame = calloutView.frame;
calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 37, -calloutViewFrame.size.height + 35);
calloutView.frame = calloutViewFrame;

[view addSubview:calloutView];

}

那么现在如何在单击特定注释标注 subview 时触发事件?

最佳答案

你可以试试这个

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{
if(![view.annotation isKindOfClass:[MKUserLocation class]]) {
CGSize calloutSize = CGSizeMake(100.0, 80.0);
UIView *calloutView = [[UIView alloc] initWithFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-calloutSize.height, calloutSize.width, calloutSize.height)];
calloutView.backgroundColor = [UIColor whiteColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(5.0, 5.0, calloutSize.width - 10.0, calloutSize.height - 10.0);
[button setTitle:@"OK" forState:UIControlStateNormal];
[button addTarget:self action:@selector(checkin) forControlEvents:UIControlEventTouchUpInside];
[calloutView addSubview:button];
[view.superview addSubview:calloutView];
}
}

引用:https://stackoverflow.com/a/17772487/2553526

关于uimap 标注 subview 上的 IOS 事件单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947102/

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