![](/img/trans.png)
[英]Swift How to Place UIStackView in a Specific Corner of ImageView
[英]Swift, add Node to SCNNode and place in corner
我嘗試將節點(圖像)放在SCNNode中。 我希望它在右上角。 但是我該如何實現呢?
所以:我想將buttonNode放在urlNode內:
let urlNode = createWebView(url: url)
urlNode.scale = SCNVector3(x: 0.3, y: 0.3, z: 0.3)
let image = UIImage(named: "arrows-expand")
let buttonNode = SCNNode(geometry: SCNPlane(width: 1, height: 1))
buttonNode.geometry?.firstMaterial?.diffuse.contents = image
urlNode.addChildNode(buttonNode)
currentNode?.addChildNode(urlNode)
createWebView:
private func createWebView(url: String) -> SCNNode {
print(url)
let webView = UIWebView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
let request = URLRequest(url: URL(string: url)!)
webView.loadRequest(request)
let tvPlane = SCNPlane(width: 4.0, height: 2.75)
tvPlane.firstMaterial?.diffuse.contents = webView
tvPlane.firstMaterial?.isDoubleSided = true
let tvPlaneNode = SCNNode(geometry: tvPlane)
var translation = matrix_identity_float4x4
translation.columns.3.z = -1.0
tvPlaneNode.eulerAngles = SCNVector3(0,0,0)
return tvPlaneNode
}
您的urlNode是一個SCNPlane,其大小為4 x 2.75。 您的buttonNode也是一個SCNPlane,其大小為1 x1。創建urlNode之后,創建您的按鈕節點並計算其位置:x = urlNode width / 2.0-imageNode width / 2.0 y = urlNode height / 2.0 + imageNode height / 2.0
let urlNode = createWebView(url: url)
let buttonNode = SCNNode(geometry: SCNPlane(width: 1, height: 1))
let image = UIImage(named: "arrows-expand")
buttonNode.geometry?.firstMaterial?.diffuse.contents = image
// Clean this up to get both the urlNode and buttonPlane SCNPlane geometry with a method of your choice here
buttonNode.postion = SCNVector3(x: urlNodePlane.width / 2.0 - buttonPlane.width / 2.0, y: urlNodePlane.height / 2.0 + buttonPlane.width / 2.0)
urlNode.addChildNode(buttonNode)
urlNode.scale = SCNVector3(x: 0.3, y: 0.3, z: 0.3)
currentNode?.addChildNode(urlNode)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.