Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.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_Sprite Kit_Swift3_Uigesturerecognizer - Fatal编程技术网

如何复制iOS主屏幕行为?

如何复制iOS主屏幕行为?,ios,sprite-kit,swift3,uigesturerecognizer,Ios,Sprite Kit,Swift3,Uigesturerecognizer,我目前正在SpriteKit中开发一款游戏,在该游戏中,我需要移动一个精灵以响应触摸(即当用户在SKView中的任何位置滑动或平移时) 我想知道平移的方向(对于滑动,我知道怎么做),这样精灵将根据平移移动(如果用户平移,我为精灵定义了一个路径,如果用户滑动,则根据滑动),iOS appdrawer中触摸的工作方式,即它对最轻微的滑动和平移做出响应(即,当您向前或向后平移时,它会决定您是否要移动到下一个屏幕) 是否有文档?(我已经阅读了UIgestureRecognitor文档,但还没有找到实现它

我目前正在SpriteKit中开发一款游戏,在该游戏中,我需要移动一个精灵以响应触摸(即当用户在SKView中的任何位置滑动或平移时)

我想知道平移的方向(对于滑动,我知道怎么做),这样精灵将根据平移移动(如果用户平移,我为精灵定义了一个路径,如果用户滑动,则根据滑动),iOS appdrawer中触摸的工作方式,即它对最轻微的滑动和平移做出响应(即,当您向前或向后平移时,它会决定您是否要移动到下一个屏幕)


是否有文档?(我已经阅读了UIgestureRecognitor文档,但还没有找到实现它的方法。)

我在MenuScene上使用了类似的功能,我有3个页面设置,用户可以滚动查看各种游戏数据。但我不想用任何轻微的触摸来移动屏幕,这会让用户感到不安。因此我只需在触摸功能中观察手指的移动,并检查移动是否超过我指定的数量作为最小移动量,如果大于,则滚动页面。在您的情况下,您可以将其处理为;如果大于最小移动量,则将其视为平移,否则将其视为滑动

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    let touch: UITouch = touches.first!
    initialTouch = touch.location(in: self.view!)
    moveAmtY = 0
    moveAmtX = 0
    initialPosition = menuScroller.position
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

    let touch: UITouch = touches.first!
    let movingPoint: CGPoint = touch.location(in: self.view!)
    moveAmtX = movingPoint.x - initialTouch.x
    moveAmtY = movingPoint.y - initialTouch.y

    //their finger is on the page and is moving around just move the scroller and parallax backgrounds around with them
    //Check if it needs to scroll to the next page when they release their finger
    menuScroller.position = CGPoint(x: initialPosition.x + moveAmtX, y: initialPosition.y)
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

    //they havent moved far enough so just reset the page to the original position
    if fabs(moveAmtX) > 0 && fabs(moveAmtX) < minimum_detect_distance {
        resetPages()
    }

    //the user has swiped past the designated distance, so assume that they want the page to scroll
    if moveAmtX < -minimum_detect_distance {
        moveLeft()
    }
    else if moveAmtX > minimum_detect_distance {
        moveRight()
    }
}
override func touchsbegind(touch:Set,带有事件:UIEvent?){
让触摸:UITouch=touch.first!
initialTouch=touch.location(在:self.view!)
moveAmtY=0
moveAmtX=0
initialPosition=menuScroller.position
}
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
让触摸:UITouch=touch.first!
让movingPoint:CGPoint=touch.location(在:self.view!)
moveAmtX=movingPoint.x-initialTouch.x
moveAmtY=movingPoint.y-initialTouch.y
//他们的手指在页面上移动,只需移动滚动条和视差背景
//当他们松开手指时,检查是否需要滚动到下一页
menuScroller.position=CGPoint(x:initialPosition.x+moveAmtX,y:initialPosition.y)
}
覆盖函数touchesend(touchs:Set,带有事件:UIEvent?){
//他们移动得不够远,所以只需将页面重置为原始位置
如果fabs(moveAmtX)>0&&fabs(moveAmtX)<最小检测距离{
重置页面()
}
//用户已刷过指定距离,因此假设他们希望页面滚动
如果moveAmtX<-最小检测距离{
左移()
}
否则,如果moveAmtX>最小检测距离{
moveRight()
}
}

感谢您的回复。