2016-07-28 73 views
1

我试过所有的东西让我的视图出现在地图视图上(见下面的代码),但它仍然不会显示出来。我不知道该怎么办。 This is the mapView at 0.5 alpha查看被卡在MapView背后

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

我已经看过这个线程:[https://stackoverflow.com/questions/13182482/bringing-a-subview-to-be-in-front-of -all-other-views](https://stackoverflow.com/questions/13182482/bringing-a-subview-to-be-in-front-of-all-other-views) – CarvicheBlack

回答

1

你有没有试过这些?

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

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

谢谢。第二个工作。我一直在寻找这个。 :) – CarvicheBlack