我已尝试过一切让我的视图显示在地图视图上(请参阅下面的代码),但它仍然无法显示。我不知道该怎么做。 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
答案 0 :(得分:1)
你有没有试过这些?
self.view.bringSubviewToFront(self.segmentedControl)
self.view.sendSubviewToBack(self.mapView)
或
self.segmentedControl?.superview.bringSubviewToFront(self.segmentedControl)
self.mapView?.superview.sendSubviewToBack(self.mapView)