我正在尝试构建一个应用程序,用户可以在其中单击地图视图顶部的导航栏中的按钮按钮项。但是,导航栏固定在页面顶部,我希望它位于中间,以便将鼠标悬停在mapview上。有什么办法做到这一点,我在stackoverflow页面上找不到答案。谢谢
我已经尝试将其添加为子视图,并且尝试更改mapview和导航栏的约束
IBOutlet weak var navBar: UINavigationItem!
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var map: MKMapView!
let manager = CLLocationManager()
var latitude: Double = 0.0
var longitude: Double = 0.0
var overlays = [MKOverlay]()
var locations = [Message]()
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.requestLocation()
manager.startUpdatingLocation()
textField.backgroundColor = UIColor.white
textField.layer.masksToBounds = false
textField.layer.shadowColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.9).cgColor
textField.layer.shadowOffset = CGSize(width: 0, height: 2)
textField.layer.shadowOpacity = 0.6
textField.backgroundColor = .white
// Do any additional setup after loading the view, typically from a nib.
map.addSubview(navBar as! UIView)
}
地图视图不会停留在页面中间。