2015-07-21 72 views
0
@IBOutlet weak var getout: UIButton! 
@IBOutlet weak var legstreet: UIImageView! 
@IBOutlet weak var viewStreett: GMSPanoramaView! 
var panoramaNear: CLLocationCoordinate2D! 
override func viewDidLoad() { 
    super.viewDidLoad() 
    panoramaNear = CLLocationCoordinate2DMake(30.274262, -97.752371) 
    //var panoramaNear = self.tmpString 
    var panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero, 
     nearCoordinate:panoramaNear)   
    self.viewStreett = panoView 
    // Do any additional setup after loading the view. 
} 

當我這樣寫時,街景無法顯示。我不得不修改 self.viewStreett = panoViewself.view = panoView.但是在這個時候UIImageView消失了。所以我的問題是如何將UIImageView添加到街景中,並且不要打擾街景的使用。如何在Google街景視圖中添加UIImageView視圖sdk for ios

回答

1

您的viewStreet將是一個加載GMSPanoramaView,因爲它沒有座標。所以你不能讓一個裝載GMSPanoramaView等於你的panoViewviewStreet = panoView不會工作)。

取而代之,您可以將viewStreet的類型更改爲UIView,現在它將像您的panoView的容器視圖一樣行爲。然後,您可以執行viewStreet.addSubview(panoView)將您的panoView添加到容器。

示例代碼:

@IBOutlet weak var viewStreet: UIView! 
    @IBOutlet weak var sampleImageView: UIImageView! 
    var panoView: GMSPanoramaView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let panoramaNear = CLLocationCoordinate2DMake(30.274262, -97.752371) 

     panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero, 
      nearCoordinate:panoramaNear) 

     viewStreet.addSubview(panoView) 
     viewStreet.sendSubviewToBack(panoView) 

     let equalWidth = NSLayoutConstraint(item: panoView, attribute: .Width, relatedBy: .Equal, toItem: viewStreet, attribute: .Width, multiplier: 1.0, constant: 0) 
     let equalHeight = NSLayoutConstraint(item: panoView, attribute: .Height, relatedBy: .Equal, toItem: viewStreet, attribute: .Height, multiplier: 1.0, constant: 0) 
     let top = NSLayoutConstraint(item: panoView, attribute: .Top, relatedBy: .Equal, toItem: viewStreet, attribute: .Top, multiplier: 1.0, constant: 0) 
     let left = NSLayoutConstraint(item: panoView, attribute: .Left, relatedBy: .Equal, toItem: viewStreet, attribute: .Left, multiplier: 1.0, constant: 0) 

     panoView.setTranslatesAutoresizingMaskIntoConstraints(false) 
     NSLayoutConstraint.activateConstraints([equalWidth, equalHeight, top, left]) 
    } 

如果你在你的應用程序中使用自動版式,你應該增加寬度,高度,頂部和左側約束你panoView

您可以在this GitHub page查看示例應用程序。

在下面的模擬器屏幕截圖中,我只需在panoView之上添加標記圖像即可。 enter image description here

相關問題