【发布时间】:2018-07-23 21:09:33
【问题描述】:
这是我的视图控制器,即使我向 CGRect 添加值也无法正常工作
import UIKit
import GoogleMaps
class ViewController: UIViewController,CLLocationManagerDelegate,
GMSMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: 52.649030,
longitude: 1.174155, zoom: 14)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
self.view = mapView
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: 52.649030,
longitude: 1.174155)
marker.title = "marker1"
marker.snippet = "city"
marker.map = mapView
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
self.view.addSubview(button)
}
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print(marker.position)
return true
}
}
那么,我的代码中是否有任何错误? 谢谢
【问题讨论】:
-
CGRect 为空。试试看:
UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) -
对不起,我是新手,这是我的第一个问题,但仍然没有显示按钮
-
添加文本或按钮背景颜色以在地图视图上查看按钮
-
兄弟,您确实需要先查看在线教程,您似乎对iOS编程相当陌生。祝你好运!
标签: ios dictionary button swift4 google-maps-sdk-ios