簡體   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