Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以恒定距离滚动节点_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios 以恒定距离滚动节点

Ios 以恒定距离滚动节点,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我想知道如何在给定距离内滚动节点,例如100像素。我已经这样做了: override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { fingerIsOnScroll = false } func roundTo(value: Int) -> Int{ var fractionNum = Double(value) / 100.0 let roundedNum

我想知道如何在给定距离内滚动节点,例如100像素。我已经这样做了:

override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {

    fingerIsOnScroll = false
}
func roundTo(value: Int) -> Int{
    var fractionNum = Double(value) / 100.0
    let roundedNum = Int(ceil(fractionNum))
    return roundedNum * 100
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
    if fingerIsOnScroll{
        for touch: AnyObject in touches {
        let touchLoc = touch.locationInNode(self)
        let prevTouchLoc = touch.previousLocationInNode(self)
        var jump = touchLoc.x - prevTouchLoc.x
        var myIntValue:Int = Int(jump)
        myIntValue = roundTo(myIntValue)

        var jumpCGFloat = CGFloat(myIntValue)

        simple.position=CGPointMake(simple.position.x + (jumpCGFloat), simple.position.y)
        }
    }
}
override func touchesend(touchs:Set,withEvent-event:UIEvent){
fingerIsOnScroll=错误
}
func roundTo(值:Int)->Int{
var fractionNum=双(值)/100.0
设roundedNum=Int(ceil(fractionNum))
返回roundedNum*100
}
覆盖功能触摸移动(触摸:设置,withEvent事件:UIEvent){
如果手指头转动{
用于触摸:触摸中的任何对象{
让touchLoc=touch.locationInNode(自身)
让PreviousLocation=touch.previousLocationInNode(自身)
var jump=touchLoc.x-prevTouchLoc.x
var myIntValue:Int=Int(跳转)
myIntValue=roundTo(myIntValue)
var jumpCGFloat=CGFloat(myIntValue)
simple.position=CGPointMake(simple.position.x+(jumpCGFloat),simple.position.y)
}
}
}

问题是,当我向左滚动时,它会向右移动,而如果我向右滚动,它甚至不会移动。谢谢

我看到你把fingerIsOnScroll设置为false,但我从来没有看到你把它设置为falsetrue@BotMaster我已经解决了这个问题,但感谢您的评论:)