我想在没有uiscrollview的sprite工具箱中滚动一个节点。
// In touchesMoved
let touch: UITouch = touches.first as! UITouch;
let location:CGPoint = touch.locationInNode(self);
let lastPosition = touch.previousLocationInNode(self)
var newLoc = selectNode.position.y + (location.y - lastPosition.y)
// Check if the top part is reached
if(newLoc < selectNodeStart){
newLoc = selectNodeStart
}
if(selectNode.position.y >= selectNodeStart){
// let sk = SKAction.moveToY(newLoc, duration: 0.1)
// selectNode.runAction(sk)
selectNode.position.y = newLoc
}如果我使用sk操作,结果是非常可怕的,但是如果没有结果,结果也是可怕的。
发布于 2015-09-07 13:41:18
在SpriteKit中,一种很好的方法是使用UIPanGestureRecognizer来检测触摸,其中您将创建一个SKActions序列,该序列将加速或减速移动。您可能必须使用update方法和/或touches来处理pan停止或另一个立即启动。不幸的是,如果您只想使用SpriteKit,就必须使用SKActions来实现这一点。
我想我也应该提一种更简单(也可能更好看)的方法来做这件事。看一看"ScrollKit",它运行得很好(尽管它确实使用了UIScrollView):https://github.com/bobmoff/ScrollKit
如果您发现UIScrollView没有传递给touchesMoved,您可以尝试一些不同的东西。
CanCancelContentTouches上将其设置为YES。override func touchesBegan(touches: NSSet, withEvent event: UIEvent){
if (!self.dragging){
self.nextResponder.touchesBegan(touches , withEvent: event)
}
else{
super.touchesBegan(touches , withEvent: event)
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent){
if (!self.dragging){
self.nextResponder.touchesMoved(touches , withEvent:event)
}
else{
super.touchesMoved(touches , withEvent: event)
}
}
override func touchesEnded(touches: NSSet, withEvent: event UIEvent){
if (!self.dragging){
self.nextResponder.touchesEnded(touches , withEvent: event)
}
else{
super.touchesEnded(touches , withEvent: event)
}
}https://stackoverflow.com/questions/32439385
复制相似问题