Как отобразить следующий пользовательский интерфейс?

#ios #swift #xcode #uiview #gmsmapview

#iOS #swift #xcode #пользовательский интерфейс #gmsmapview

Вопрос:

На одной из моих страниц у меня есть следующая настройка:

https://imgur.com/a/Lzfnmm0

На текущей странице отображается MapView с Картами Google, и я делаю вид, что отображаю UIView поверх MapView… Я пробовал что угодно, но MapView всегда отображается поверх пользовательского интерфейса. Как я могу это исправить?

Это код моей страницы:

 import UIKit
import CoreLocation
import GoogleMaps
import GooglePlaces

class GoogleMapPage: UIViewController, CLLocationManagerDelegate{

    var placesClient: GMSPlacesClient!
    var addressName: String? = nil
    lazy var geocoder = CLGeocoder()
    var latitude: Double = 0.0
    var longitude: Double = 0.0


    @IBOutlet weak var mapView: GMSMapView!
    @IBOutlet weak var cameraButton: UIButton!
    @IBOutlet weak var menuButton: UIButton!
    @IBOutlet weak var sideMenu: UIView!


    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()

        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestLocation()
        placesClient = GMSPlacesClient.shared()

        mapView.bringSubviewToFront(cameraButton)
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
        if let location = locations.first {
            createMap(location.coordinate.longitude, location.coordinate.latitude)
            self.longitude = location.coordinate.longitude
            self.latitude = location.coordinate.latitude
        }
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        let alertController = UIAlertController(title: "Location Error", message: error.localizedDescription, preferredStyle: .alert)
        let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
        alertController.addAction(okayAction)
        self.present(alertController, animated: true, completion: nil)
    }

    func createMap(_ longitude: Double, _ latitude: Double){
        let position = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
        let marker = GMSMarker(position: position)
        let camera = GMSCameraPosition.camera(withLatitude: latitude, longitude: longitude, zoom: 12.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        marker.map = mapView
        marker.title = "Your Position"
        mapView.addSubview(cameraButton)
        mapView.addSubview(menuButton)

        view = mapView

        let location = CLLocation(latitude: latitude, longitude: longitude)

        // Geocode Location
        geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
            // Process Response
            print(placemarks as Any)
        }

    }
}
 

Ответ №1:

Вы добавляете MenuView и кнопки внутри MapView, а не закрываете вид карты. MenuView является подвидом Mapview, поэтому он не отображается

Комментарии:

1. Я тоже думал об этом. Но когда я пытаюсь вывести их, они вынуждены заходить внутрь mapview… Есть идеи, почему?

2. Используйте цвет документа в левой части, отображаемый на опубликованном вами изображении. Перетащите menuview за пределы отображения Mapview в разделе «Страница Google Maps»

3. Я пробовал это, но он позволяет мне размещать боковое меню только под первым ответчиком, и это выводит часть из экрана.

4. Попробуйте добавить его над Mapview. А затем в вашей функции viewwillappear напишите view.bringSubviewToFront(sideMenu)