视图卡在MapView后面

时间:2016-07-28 14:59:52

标签: ios swift uiview uiview-hierarchy

我已尝试过一切让我的视图显示在地图视图上(请参阅下面的代码),但它仍然无法显示。我不知道该怎么做。 This is the mapView at 0.5 alpha

segmentedControl = DPSegmentedControl.init(
            FrameWithoutIcon: CGRectMake(307.5, 566, 235, 37.5),
            items: ["Standard", "Satellite", "Hybrid"],
            backgroundColor: UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1),
            thumbColor: UIColor.init(hex: "#B60002"),
            textColor: UIColor(hex: "#808080"),
            selectedTextColor: UIColor(hex: "#FFFFFF"))
        segmentedControl.alpha = 0

        segmentedControl.selectedIndex = 0

        segmentedControl.addTarget(self, action: #selector(self.tapSegment(_:)), forControlEvents: .ValueChanged)
        self.view.insertSubview(self.segmentedControl, belowSubview: self.hoverBar)
        UIApplication.sharedApplication().keyWindow!.bringSubviewToFront(self.segmentedControl)
        UIApplication.sharedApplication().keyWindow!.sendSubviewToBack(self.mapView)

当我使用z位置时,会出现视图,但它不允许任何触摸操作(它是自定义分段控件)。

self.segmentedControl.layer.zPosition = self.mapView.layer.zPosition + 1

1 个答案:

答案 0 :(得分:1)

你有没有试过这些?

self.view.bringSubviewToFront(self.segmentedControl)
self.view.sendSubviewToBack(self.mapView)

self.segmentedControl?.superview.bringSubviewToFront(self.segmentedControl)
self.mapView?.superview.sendSubviewToBack(self.mapView)