【发布时间】:2015-10-22 13:34:57
【问题描述】:
我试图在 Google 地图上添加一个按钮。我尽我所能,但没有人能帮助我。在 Xcode 预览中,它显示在顶部,但在运行应用程序后,它位于谷歌地图下方。
应用运行后的图片
它在 XCODE 中的样子
地图代码
import UIKit
import GoogleMaps
class HomeViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var scrollView: UIScrollView!
@IBAction func refreshLocation(sender: AnyObject) {
locationManager.startUpdatingLocation()
}
@IBOutlet weak var gMapView: GMSMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
self.scrollView.contentSize=CGSizeMake(320, 700)
let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 17)
gMapView.camera = camera
gMapView.myLocationEnabled = true
self.view.addSubview(gMapView)
let marker = GMSMarker()
marker.map = self.gMapView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension HomeViewController {
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == CLAuthorizationStatus.AuthorizedAlways {
locationManager.startUpdatingLocation()
gMapView.myLocationEnabled = true
gMapView.settings.myLocationButton = true
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
gMapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}
}
【问题讨论】:
-
另外,如果您以编程方式操作子视图,请分享代码。有关约束的信息也会有所帮助。
-
我正在使用自动布局做所有事情。没有任何程序。我是 iOS 新手
-
是的,我可以看到您正在使用自动布局。在您创建地图的位置共享代码。还告诉我们你在 control.png 上使用了哪些约束(我假设你想把哪个 Imageview 放在首位)。此外,UIImageView 不是 UIButton。
-
我已经更新了代码
-
在分配 view=mapView 之前需要添加子视图。
标签: ios xcode swift google-maps swift2