有很多這方面的文章,但無論出於什麼原因,我似乎無法得到正確的轉換正確的序列。我試圖讓UISliders直接進入SKLabels下面。轉換UIKit和SpriteKit之間的CGPoints困境:SKNodes旁邊的UIView
正如你可以在圖片中看到,滑塊的一個不顯示在所有的,另一種是在完全錯誤的地方(音量滑塊是尋求標籤附近):
這是我在得到這個恰當的電流的嘗試,雖然我已經試過這讓我無處一些其他配置:
class GameScene: SKScene {
let seekSlider = UISlider(frame: CGRect(x: 0, y: 0, width: 200, height: 15))
let volSlider = UISlider(frame: CGRect(x: 0, y: 0, width: 200, height: 15))
override func didMove(to view: SKView) {
removeAllChildren() // Delete this in your actual project.
// Add some labels:
let seekLabel = SKLabelNode(text: "Seek")
seekLabel.setScale(3)
seekLabel.verticalAlignmentMode = .center
seekLabel.position = CGPoint(x: frame.minX + seekLabel.frame.width/2,
y: frame.maxY - seekLabel.frame.height)
let volLabel = SKLabelNode(text: "Volume")
volLabel.setScale(3)
volLabel.verticalAlignmentMode = .center
volLabel.position = CGPoint(x: frame.minX + volLabel.frame.width/2,
y: frame.minY + volLabel.frame.height + volSlider.frame.height)
/* CONVERSION WOES BELOW: */
// Configure sliders:
let seekOrigin = convertPoint(toView: convert(seekLabel.position, from: self))
seekSlider.frame = CGRect(origin: seekOrigin, size: CGSize(width: 200, height: 15))
seekSlider.value = 1
let volOrigin = convertPoint(fromView: CGPoint(x: volLabel.frame.minX, y: volLabel.frame.minY))
seekSlider.frame = CGRect(origin: volOrigin, size: CGSize(width: 200, height: 15))
seekSlider.value = 0
// Scene stuff:
view.addSubview(seekSlider)
view.addSubview(volSlider)
addChild(seekLabel)
addChild(volLabel)
}
}
你試圖達到什麼樣的佈局?滑塊是否應該放在每個標籤下方? – nathan
@nathan是的,雖然在這一點上,只是有正確的標籤附近的滑塊將是一個很好的開始:] – Fluidity
HELL,我甚至將兩個滑塊_being在該死的screen_上作爲一個很好的答案:D – Fluidity