自定义 iOS 弹出气泡

4

我正在开发具有地图视图功能的应用程序。 我想在地图视图上显示自定义标记图像,点击后打开带有图像和标题的自定义弹出气泡。 点击该气泡视图后,我想执行一些功能。 如何实现这一点? 感谢您的任何帮助。


3个回答

7

访问CocoaControls获取自定义控件,相信你会找到符合需求的有用内容。

以下是来自CocoaControls的一些搜索结果:


自定义图钉图片

关于这个问题,已经有类似的问题在stackoverflow上得到了解答。这里这里等等都有。我敢说你能在其中找到你需要的答案。基本上,代码如下:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

    NSString *annotationIdentifier = @"CustomViewAnnotation";
    MKAnnotationView* annotationView = [mapview dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    if(!annotationView)
    {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
                                                  reuseIdentifier:annotationIdentifier]];
    }
    annotationView.image = [UIImage imageNamed:@"map_location_pin.png"];
    annotationView.canShowCallout= YES;

    return annotationView;
}

我已经将自定义图像设置为注释,现在我想在单击该图像时打开自定义气泡。如何实现这一点? - user2996143
您可以使用 MKMapViewDelegate 的方法 mapView:didSelectAnnotationView: 处理点击操作并通过该方法显示弹出窗口。 - aksh1t
哦,如果你正在显示自己的定制标注,那么你需要通过设置 canShowCalloutNO 来关闭默认标注。尝试调整代码,看看是否达到了你想要的效果。 - aksh1t
谢谢您的回复。我会尝试一下。 - user2996143
很高兴能够帮到你。如果解决了你的问题,请考虑接受这个答案。谢谢! - aksh1t


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接