【问题标题】:Make the subview at centre or some height from the top使子视图位于中心或距顶部的某个高度
【发布时间】:2018-12-22 20:47:41
【问题描述】:

@IBOutlet weak var viewmap: GMSMapView!

我的 vc 中有一个名为 viewmap 的地图视图。还有一个名为mapInfoWindow 的uiview。现在,当用户单击我的地图的任何图钉时,该特定图钉详细信息将显示在 mapInfoWindow 中。现在该位置位于顶部,我的mapInfoWindow 正在隐藏我的搜索栏。

我需要使位置从我的顶部开始。这是代码:

func mapView(_ mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView!
    {
        print("markerInfoWindow called!!!")
        let firstview = UIView.init(frame: CGRect(x: 0, y: 0, width: 275, height: 195))
        self.mapInfoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?[0] as! CustomInfoWindow

        self.mapInfoWindow.ClickForMore.text = "click_here_for_more".localized
        marker.tracksInfoWindowChanges = true

// data for fetching details
     self.mapInfoWindow.bgview.layer.shadowColor = UIColor.black.cgColor
        self.mapInfoWindow.bgview.layer.shadowOpacity = 0.4
        self.mapInfoWindow.bgview.layer.shadowOffset = CGSize.zero
        self.mapInfoWindow.bgview.layer.shadowRadius = 2
        self.mapInfoWindow.bgview.backgroundColor = UIColor.clear


        firstview.addSubview(self.mapInfoWindow)

        return firstview
    }

我怎样才能做到这一点。我尝试给 y 值但没有工作。有什么想法吗?

也试过了:

mapInfoWindow.center.y = firstview.center.y - 80 - 不工作

提前致谢

【问题讨论】:

    标签: ios swift gmsmapview


    【解决方案1】:

    您不能设置视图的单个框架属性,并且中心应该拼写为中心。这是一个extension,可让您定位视图的各个值。

    使用扩展,上面的例子可以写成:

    mapInfoWindow.centerY = firstview.centerY - 80

    【讨论】:

    • mapInfoWindow.centerY = firstview.centerY - 80 这是隐藏我的 uiview 一半
    • @david 我不知道你说的“这隐藏了我的 uiview 一半”是什么意思
    • 我的mapInfoWindow 高度从顶部减小。
    • @david 该扩展还允许您设置mapInfoWindow 高度,例如mapInfoWindow.height = 100。我不清楚问题是什么,也许截图会有所帮助。
    猜你喜欢
    • 2020-11-27
    • 2015-09-12
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    相关资源
    最近更新 更多