简体   繁体   English

将UIButton固定到MapView

[英]pin a UIButton to a MapView

I make a UIButton over an annotationView like this below: 我在annotationView上创建一个UIButton,如下所示:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGPoint point = [mainMapView convertCoordinate:sac.coordinate toPointToView:self.smallView];
button.frame = CGRectMake(point.x - 30, point.y - 30, 60, 60);

It works great, but when I move the map, the buttons do not move with the map. 它工作得很好,但是当我移动地图时,按钮不随地图移动。 Is there a way to draw the button with a CGRectMake that puts the button.frame on the map instead of the view? 有没有办法用CGRectMake绘制按钮,将button.frame放在地图而不是视图上?

You really should use The MKMapAnnotation stuff to accomplish that. 你真的应该使用MKMapAnnotation的东西来实现这一目标。 this link walks you through the basics of setting up the delegates needed. 此链接将指导您完成设置所需代理的基础知识。 Basically all work to keep the button in a location has been done for you--you just have to take advantage of it. 基本上所有将按钮保持在某个位置的工作都已经为您完成 - 您只需要利用它。 This class reference shows how you can set an image for your overlay view and various other things. 此类参考显示了如何为叠加视图和其他各种事物设置图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM