您的viewStreet
將是一個加載GMSPanoramaView
,因爲它沒有座標。所以你不能讓一個裝載GMSPanoramaView
等於你的panoView
(viewStreet = 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
之上添加標記圖像即可。