2016-07-28 57 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