我有三个UISlider
,分别是slider 1
:缩放,slider 2
:调整左/右和slider 3
:调整顶部/底部。
调整slider 1
(比例)时,调整slider 2
(左/右)scnnode
时未调整相同的比例值,它将减小为原始比例值。
这是我的三个滑块值的代码:
@IBAction func didChangedSlider(_ sender: Any) {
switch slider.value {
case 0 ... 25 :
earsNode1.scale = SCNVector3(0.0011, 0.0011, 0.0011)
earsNode.scale = SCNVector3(0.0010, 0.0010, 0.0010)
earsNode.position = SCNVector3(-0.08, -0.035, -0.12)
earsNode1.position = SCNVector3(0.077, -0.035, -0.12)
isSizeIncreased = false
case 25 ... 50 :
earsNode1.scale = SCNVector3(0.0014, 0.0014, 0.0014)
earsNode.scale = SCNVector3(0.0014, 0.0014, 0.0014)
earsNode.position = SCNVector3(-0.08, -0.040, -0.12)
earsNode1.position = SCNVector3(0.077, -0.040, -0.12)
isSizeIncreased = true
case 50 ... 75 :
earsNode1.scale = SCNVector3(0.002, 0.002, 0.002)
earsNode.scale = SCNVector3(0.002, 0.002, 0.002)
earsNode.position = SCNVector3(-0.08, -0.050, -0.12)
earsNode1.position = SCNVector3(0.077, -0.050, -0.12)
isSizeIncreased = true
case 75 ... 100 :
earsNode1.scale = SCNVector3(0.003, 0.003, 0.003)
earsNode.scale = SCNVector3(0.003, 0.003, 0.003)
earsNode.position = SCNVector3(-0.08, -0.064, -0.12)
earsNode1.position = SCNVector3(0.077, -0.064, -0.12)
isSizeIncreased = true
default:
print("slider value \(slider.value)")
}
}
// slider2 - left/right
@IBAction func didChangedSliderLeftOrRight(_ sender: Any) {
switch slider2.value {
case 0 ... 25:
earsNode.position = SCNVector3(-0.083, -0.035, -0.099)
earsNode1.position = SCNVector3(0.083, -0.035, -0.099)
case 25 ... 50:
earsNode.position = SCNVector3(-0.081, -0.035, -0.099)
earsNode1.position = SCNVector3(0.081, -0.035, -0.099)
case 50 ... 75:
earsNode.position = SCNVector3(-0.077, -0.035, -0.099)
earsNode1.position = SCNVector3(0.077, -0.035, -0.099)
case 75 ... 100:
earsNode.position = SCNVector3(-0.073, -0.035, -0.099)
earsNode1.position = SCNVector3(0.073, -0.035, -0.099)
default:
print("slider2 value \(slider2.value)")
}
}
// slider3 - top/bottom
@IBAction func didChangedSliderTopOrBottom(_ sender: Any) {
switch slider3.value {
case 0 ... 25:
earsNode.position = SCNVector3(-0.079, -0.027, -0.099)
earsNode1.position = SCNVector3(0.079, -0.027, -0.099)
case 25 ... 50:
earsNode.position = SCNVector3(-0.079, -0.031, -0.099)
earsNode1.position = SCNVector3(0.079, -0.031, -0.099)
if isSizeIncreased {
earsNode.position = SCNVector3(-0.08, -0.040, -0.12)
earsNode1.position = SCNVector3(0.077, -0.040, -0.12)
}
case 50 ... 75:
earsNode.position = SCNVector3(-0.079, -0.035, -0.099)
earsNode1.position = SCNVector3(0.079, -0.035, -0.099)
if isSizeIncreased {
earsNode.position = SCNVector3(-0.08, -0.054, -0.12)
earsNode1.position = SCNVector3(0.077, -0.054, -0.12)
}
case 75 ... 100:
earsNode.position = SCNVector3(-0.079, -0.039, -0.099)
earsNode1.position = SCNVector3(0.079, -0.039, -0.099)
if isSizeIncreased {
earsNode.position = SCNVector3(-0.08, -0.060, -0.12)
earsNode1.position = SCNVector3(0.077, -0.060, -0.12)
}
default:
print("slider3 value \(slider3.value)")
}
}
}
这是我的屏幕截图
我的问题是,当用户更改任何滑块值时,其值并未从调整后的滑块的最后位置改变。 滑块值应从已调整的位置调整。
答案 0 :(得分:1)
复制/粘贴并以Xcode保存此文件https://gist.github.com/jeremyconkin/a3909b2d3276d1b6fbff02cefecd561a
在滑块中使用Vector Math时(我仅重写1st):
@IBAction func didChangedSlider(_ sender: Any) {
switch slider.value {
case 0 ... 25 :
earsNode1.scale += SCNVector3(0.0011, 0.0011, 0.0011)
earsNode.scale += SCNVector3(0.0010, 0.0010, 0.0010)
earsNode.position += SCNVector3(-0.08, -0.035, -0.12)
earsNode1.position += SCNVector3(0.077, -0.035, -0.12)
isSizeIncreased = false
case 25 ... 50 :
earsNode1.scale += SCNVector3(0.0014, 0.0014, 0.0014)
earsNode.scale += SCNVector3(0.0014, 0.0014, 0.0014)
earsNode.position += SCNVector3(-0.08, -0.040, -0.12)
earsNode1.position += SCNVector3(0.077, -0.040, -0.12)
isSizeIncreased = true
case 50 ... 75 :
earsNode1.scale += SCNVector3(0.002, 0.002, 0.002)
earsNode.scale += SCNVector3(0.002, 0.002, 0.002)
earsNode.position += SCNVector3(-0.08, -0.050, -0.12)
earsNode1.position += SCNVector3(0.077, -0.050, -0.12)
isSizeIncreased = true
case 75 ... 100 :
earsNode1.scale += SCNVector3(0.003, 0.003, 0.003)
earsNode.scale += SCNVector3(0.003, 0.003, 0.003)
earsNode.position += SCNVector3(-0.08, -0.064, -0.12)
earsNode1.position += SCNVector3(0.077, -0.064, -0.12)
isSizeIncreased = true
default:
print("slider value \(slider.value)")
}
}