如何将文本字段放在 google 地图 iOS 之上
how to put a text field on top of google maps iOS
我的目标是在 google 地图 iOS 上放置一个文本字段,但似乎不起作用
当我 运行 应用程序时,Google 地图
上方不存在文本字段
代码
import UIKit
import GoogleMaps
class ViewController: UIViewController {
@IBOutlet var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
不是将 UITextField
添加为 MapView
的 subView
,而是将两者添加到同一个 UIView
中,只需将 UITextfield
放在 [=15= 上].改成这样
这是对 storyboard
执行相同操作的超级简单的解决方案。
添加约束
注意:如果您在查看 GIF 时遇到问题,请下载并分离框架
输出
我的目标是在 google 地图 iOS 上放置一个文本字段,但似乎不起作用
当我 运行 应用程序时,Google 地图
上方不存在文本字段代码
import UIKit
import GoogleMaps
class ViewController: UIViewController {
@IBOutlet var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
不是将 UITextField
添加为 MapView
的 subView
,而是将两者添加到同一个 UIView
中,只需将 UITextfield
放在 [=15= 上].改成这样
这是对 storyboard
执行相同操作的超级简单的解决方案。
添加约束
注意:如果您在查看 GIF 时遇到问题,请下载并分离框架
输出