简体   繁体   English

如何在iOS Swift中处理多个UISlider值?

[英]how to handle multiple UISlider value in iOS Swift?

I have three UISlider namely slider 1 : to scale, slider 2 : to adjust left/right and slider 3 : to adjust top/bottom position. 我有三个UISliderslider 1 :缩放, slider 2 :调整左/右, slider 3 :调整顶部/底部。

When slider 1 (scale) is adjusted, when adjusting slider 2 (left/right) scnnode is not adjusted same scale value, it reduces to original scale value. 调整slider 1 (比例)时,未将调整slider 2 (左/右) scnnode调整为相同比例值时,会减小到原始比例值。

here is my code of three slider value: 这是我的三个滑块值的代码:

 @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)")

    }
  }
}

here is my screenshot 这是我的截图

在此处输入图片说明

My issue is when user change any slider value, its not changing from last position of slider adjusted. 我的问题是,当用户更改任何滑块值时,它不会从调整后的滑块的最后位置开始改变。 Slider value should be adjusted from already adjusted position. 滑块值应从已调整的位置调整。

Copy/Paste and Save in Xcode this file https://gist.github.com/jeremyconkin/a3909b2d3276d1b6fbff02cefecd561a 复制/粘贴并以Xcode保存此文件https://gist.github.com/jeremyconkin/a3909b2d3276d1b6fbff02cefecd561a

When use Vector Math in your sliders (I rewrite only 1st): 在滑块中使用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)")
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM