ios点击大头针气泡不弹出_iOS高德地图之自定义大头针and泡泡view
啥都不说先看效果图demo
IMG_0270.PNG
先来说说如何自定义大头针以及点击大头针时弹出的泡泡view
一 : 自定义大头针
新建CustomAnnotationView 继承自MAAnnotationView
添加属性
重写- (id)initWithAnnotation:(id)annotation reuseIdentifier:(NSString *)reuseIdentifier
重写- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 解决泡泡view超出父控件事件响应问题
重写- (void)setSelected:(BOOL)selected animated:(BOOL)animated
二 : 自定义泡泡View
新建自定义气泡类 CustomCalloutView,继承 UIView。
在 CustomCalloutView.h 中定义数据属性,包含:图片、商户名和商户地址。(随便你怎么搞,在这里我就搞了一个xib)
Snip20170620_1.png
在上面新建的CustomAnnotationView.h中定义自定义气泡属性
#import "CustomCalloutView.h"
@interface CustomAnnotationView : MAAnnotationView
@property (nonatomic, readonly) CustomCalloutView *calloutView;
@end
重写选中方法- (void)setSelected:(BOOL)selected animated:(BOOL)animated。选中时新建并添加calloutView,传入数据;非选中时删除calloutView。
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
if (self.selected == selected)
{
return;
}
if (selected)
{
if (self.calloutView == nil)
{
/* Construct custom callout. */
self.calloutView = [CustomCalloutView calloutView];
self.calloutView.frame = CGRectMake(0, 0, kCalloutWidth, kCalloutHeight);
self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
-CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
}
[self addSubview:self.calloutView];
}
else
{
[self.calloutView removeFromSuperview];
}
[super setSelected:selected animated:animated];
}
修改ViewController.m,在MAMapViewDelegate的回调方法mapView:viewForAnnotation中的修改annotationView的类型
#pragma mark - MAMapViewDelegate
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *customReuseIndetifier = @"customReuseIndetifier";
CustomAnnotationView *annotationView = (CustomAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndetifier];
if (annotationView == nil)
{
annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:customReuseIndetifier];
// must set to NO, so we can show the custom callout view.
annotationView.canShowCallout = NO;
annotationView.draggable = YES;
annotationView.calloutOffset = CGPointMake(0, -5);
}
return annotationView;
}
return nil;
}
用于调整泡泡view显示不全问题
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
{
/* Adjust the map center in order to show the callout view completely. */
if ([view isKindOfClass:[CustomAnnotationView class]]) {
CustomAnnotationView *cusView = (CustomAnnotationView *)view;
CGRect frame = [cusView convertRect:cusView.calloutView.frame toView:self.mapView];
frame = UIEdgeInsetsInsetRect(frame, UIEdgeInsetsMake(kCalloutViewMargin, kCalloutViewMargin, kCalloutViewMargin, kCalloutViewMargin));
if (!CGRectContainsRect(self.mapView.frame, frame))
{
/* Calculate the offset to make the callout view show up. */
CGSize offset = [self offsetToContainRect:frame inRect:self.mapView.frame];
CGPoint theCenter = self.mapView.center;
theCenter = CGPointMake(theCenter.x - offset.width, theCenter.y - offset.height);
CLLocationCoordinate2D coordinate = [self.mapView convertPoint:theCenter toCoordinateFromView:self.mapView];
[self.mapView setCenterCoordinate:coordinate animated:YES];
}
}
}
ios点击大头针气泡不弹出_iOS高德地图之自定义大头针and泡泡view相关推荐
- ios点击大头针气泡不弹出_百度地图使用(二)自定义大头针和弹出气泡
百度地图使用(二)自定义大头针和弹出气泡 (2014-08-19 10:37:09) 标签: 时尚 分类: IOS http://www.aichengxu.com/article/系统优化/1149 ...
- ios点击大头针气泡不弹出_高德 ios 自定义气泡添加点击事件无效问题
在使用高德地图sdk开发的时候,需要自定义气泡吹出框,发现气泡添加的点击事件或者button都没响应. 原因:自定义的气泡是添加到大头针上的,而大头针的size只有下面很小一部分,所以calloutV ...
- ios点击大头针气泡不弹出_画家双手抖不停,画不了画丢了工作,却迎合抖动创造出一个个奇迹...
画家双手抖不停,画不了画还丢了工作,却迎合抖动创造出一个个奇迹! ▲他用大头针在香蕉上画画. 有这么一个画家,他拿着大头针,在香蕉上画画,红爆了网络,并且还出了一本书叫<给香蕉纹身>,教大 ...
- ios点击大头针气泡不弹出_地图大头针气泡点击事件
地图大头针气泡点击事件 项目中需要实现点击地图中大头针点击后出现气泡的点击事件,使用系统的方法一直没办法实现,最后发现一个很取巧的方案去解决了这个问题. - (MKAnnotationView *)m ...
- html5地图大头针,iOS高德地图之自定义大头针and泡泡view
啥都不说先看效果图demo IMG_0270.PNG 先来说说如何自定义大头针以及点击大头针时弹出的泡泡view 一 : 自定义大头针 新建CustomAnnotationView 继承自MAAnno ...
- android点击弹出滑动条,IndicatorSeekBar Android自定义SeekBar,滑动时弹出气泡指示器显示进度...
overview.png 之前在网上看到了当Slider控件在滑动时会弹出气泡指示器,觉得很有趣,于是就进行拓展,就有了下面介绍的一个安卓控件:IndicatorSeekBar.先附上Indicato ...
- 实现php a标签文件,HTML_如何点击a标签实现弹出input file上传文件对话框,html 复制代码代码如下: SPAN - phpStudy...
如何点击a标签实现弹出input file上传文件对话框 html 复制代码代码如下: <div> <a href="###">添加图片a> < ...
- 在未启动程序情况 点击视图设计器 弹出未将对象引用窗体的解决方案
请问下 在未运行程序情况 点击视图设计器 弹出未将对象引用窗体 解决方案: 1.看后台进程是不是相关的进程在启动,如果有关闭进程:重启vs,即可 2.重启电脑 转载于:https://www.cn ...
- 【土旦】vue 解决ios H5底部输入框 获取焦点时弹出虚拟键盘挡住输入框 以及监听键盘收起事件...
问题描述 im聊天H5页面,在iOS系统下,inpu获取焦点弹出系统虚拟键盘时,会出现挡住input的情况,十分影响用户体验. bug图 解决方法: html: <input type=&quo ...
最新文章
- 庆祝一下,基于JXTA的P2P文件共享传输文件测试成功。
- 【按住你的心】——Android开发CheckBoxRadioButton控件的简单使用
- 关机充电如何实现短按pwrkey灭屏
- Python 自带IDLE中调试程序
- java光标移动函数_文件内光标的移动 函数基础 定义函数的三种形式 函数的返回值 调用方式...
- 通过printf从目标板到调试器的输出
- 最短路径算法详细介绍
- 《JavaScript征途》广泛征集读后感创作者,参与有奖!
- 《SAP后勤模块实施攻略—SAP在生产、采购、销售、物流中的应用》——3.3 MRP结果评估概览...
- win10商店下载位置_win10应用商店下载的东西在哪
- Linux初级入门百篇--lsof工具
- 10天背诵英文10000单词
- Mac免费屏保 Brooklyn 苹果logo
- 已更新或删除的行值要么不能使该行成为唯一行,要么改变了多个行(2行)
- 机器学习助推分子动力学模拟
- “洋记者”眼中的中国航天员:永不放弃的梦想
- 所有者权益和资产的区别是什么?
- ChatGPT APP来了,还可以直接订阅Plus账号,操作流程都这篇里面
- 项目成本管理-成本控制工具技术:挣值管理
- Android-垂直上下滚动的TextView
热门文章
- javaserver_如何在JavaServer Pages中使用Salesforce REST API
- Java和JavaScript之间的区别
- Java单依赖性Dockerized HTTP端点
- 在Ubuntu 18.04上实际安装OpenJDK 11
- java云端部署_Jelastic Java云端平台
- java 模块化_Java模块化方法–模块,模块,模块
- 使用Spring的缓存管理器缓存Web内容
- Java性能调优调查结果(第二部分)
- 如何使用新的Apache Http Client发出HEAD请求
- 在OpenShift上将JMS与JBoss A-MQ结合使用。 从远程客户端和加密中学到的经验教训。...