繁体   English   中英

将UIButton固定到MapView

[英]pin a UIButton to a MapView

我在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);

它工作得很好,但是当我移动地图时,按钮不随地图移动。 有没有办法用CGRectMake绘制按钮,将button.frame放在地图而不是视图上?

你真的应该使用MKMapAnnotation的东西来实现这一目标。 此链接将指导您完成设置所需代理的基础知识。 基本上所有将按钮保持在某个位置的工作都已经为您完成 - 您只需要利用它。 此类参考显示了如何为叠加视图和其他各种事物设置图像。

暂无
暂无

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

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