swift – touchesEnded不被认可

swift – touchesEnded不被认可,第1张

概述当我用touchesBegan()调用时 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { print("TOUCH_BEGAN")} 我得到了打印声明. 我注意到,如果我不移动接触点, override func touchesEnded(touches: Set<UIT 当我用touchesBegan()调用时

overrIDe func touchesBegan(touches: Set<UItouch>,withEvent event: UIEvent?) {        print("touch_BEGAN")}

我得到了打印声明.
我注意到,如果我不移动接触点,

overrIDe func touchesEnded(touches: Set<UItouch>,withEvent event: UIEvent?) {        print("touch_ENDED")}

没有被召唤,但是当我移动接触点时.调用touchesEnded()需要一些最小的移动吗?如果是这样,有没有办法覆盖这个,以确保始终调用touchesEnded()?

完整的代码太长了,无法添加,但下面多一点:

import SpriteKitimport UIKitimport Foundationclass GameScene: SKScene,SKPhysicsContactDelegate {    // MARK: PropertIEs    var touchstart: CGPoint?    let minSwipedistance:CGfloat = 22    var distance: CGfloat = 0    overrIDe func dIDMovetoVIEw(vIEw: SKVIEw) {        super.dIDMovetoVIEw(vIEw)        //...        // MARK: INCLUDE SWIPE GESTURES        let swipeRight: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: Selector("swipedRight:"))        swipeRight.direction = .Right        swipeRight.cancelstouchesInVIEw = false        swipeRight.delaystouchesEnded = false        vIEw.addGestureRecognizer(swipeRight)        let swipeleft: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: Selector("swipedleft:"))        swipeleft.direction = .left        swipeleft.cancelstouchesInVIEw = false        swipeleft.delaystouchesEnded = false        vIEw.addGestureRecognizer(swipeleft)        let swipeUp: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: Selector("swipedUp:"))        swipeUp.direction = .Up        swipeUp.cancelstouchesInVIEw = false        swipeUp.delaystouchesEnded = false        vIEw.addGestureRecognizer(swipeUp)        let swipeDown: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self,action: Selector("swipedDown:"))        swipeDown.direction = .Down        swipeDown.cancelstouchesInVIEw = false        swipeDown.delaystouchesEnded = false        vIEw.addGestureRecognizer(swipeDown)    }    // MARK: ******* User Interaction ******    overrIDe func touchesBegan(touches: Set<UItouch>,withEvent event: UIEvent?) {        if let touch = touches.first {            touchstart = touch.locationInNode(self)            let location = touch.locationInNode(self)            let node = nodeAtPoint(location)        }    }    overrIDe func touchesMoved(touches: Set<UItouch>,withEvent event: UIEvent?) {    }    overrIDe func touchesCancelled(touches: Set<UItouch>?,withEvent event: UIEvent?) {        }    overrIDe func touchesEnded(touches: Set<UItouch>,withEvent event: UIEvent?) {        if let touch = touches.first,start = touchstart {            let location = touch.locationInNode(self)            // Compute the distance between the two touches            let dx = location.x - start.x            let dy = location.y - start.y            distance = sqrt(dx*dx + dy*dy)            if distance < minSwipedistance {                let node = nodeAtPoint(location)                print("NODE name: \(node.name)")            }        }        // reset the initial location        touchstart = nil    }    // MARK: handle swipes    func swipedRight(sender: UISwipeGestureRecognizer) {        print("swiped right")    }    func swipedleft(sender: UISwipeGestureRecognizer) {        print("swiped left")    }    func swipedUp(sender: UISwipeGestureRecognizer) {        print("swiped up")    }    func swipedDown(sender: UISwipeGestureRecognizer) {        print("swiped down")    }}
解决方法 您无法确保调用touchesEnded,因为可能会调用touchesCancelled.您应该始终在两者中实现结束功能. 总结

以上是内存溢出为你收集整理的swift – touchesEnded不被认可全部内容,希望文章能够帮你解决swift – touchesEnded不被认可所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存