义乌个人兼职做建设网站查建筑公司网站
web/
2025/10/2 15:52:44/
文章来源:
义乌个人兼职做建设网站,查建筑公司网站,做盗号网站,网站流量转换啥都不说先看效果图demoIMG_0270.PNG先来说说如何自定义大头针以及点击大头针时弹出的泡泡view一 : 自定义大头针新建CustomAnnotationView 继承自MAAnnotationView添加属性重写- (id)initWithAnnotation:(id)annotation reuseIdentifier:(NSString *)reuseIdentifier重写- (BO…啥都不说先看效果图demoIMG_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.hinterface CustomAnnotationView : MAAnnotationViewproperty (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];}}}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/85692.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!