gpt4 book ai didi

ios - 滑动手势识别器在 SKScene 中间歇性工作

转载 作者:行者123 更新时间:2023-11-30 12:54:43 25 4
gpt4 key购买 nike

我有一个 SKScene,其中有几个滑动手势识别器,但滑动手势很少被识别,我不知道为什么。这是我的代码:

class MyScene: SKScene
{
weak var member: MySceneDelegate?
var selectedNode = SKSpriteNode()
var backgroundSprite: MovingBackground!
var myEmitter = SKEmitterNode()
var goingUp: Bool = true
var work: Int = 0
var i = 0.0
var decal: SKSpriteNode!
var startYPosition = 690 //460 is halfway
var myTimer: Timer!
var yStart: CGFloat = 0.0
var count = 0
var currentVal = 1
var startTime = Date()
var xAxisLabelDisplayIncrement = 60.0
var interval = 5.0
var intervalCounter = 0.0
var swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(MyScene.swipe(_:)))
var swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(MyScene.swipe(_:)))

override func didMove(to view: SKView)
{
//self.view?.isUserInteractionEnabled = true
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(MyScene.handlePanFrom(_:)))
self.view!.addGestureRecognizer(gestureRecognizer)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(MyScene.handleTap(_:)))
self.view!.addGestureRecognizer(tapGestureRecognizer)
swipeRight.addTarget(self, action: #selector(MyScene.swipe(_:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
swipeRight.numberOfTouchesRequired = 1
self.view!.addGestureRecognizer(swipeRight)

swipeLeft.addTarget(self, action: #selector(MyScene.swipe(_:)))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
swipeLeft.numberOfTouchesRequired = 1
self.view!.addGestureRecognizer(swipeLeft)
}
func swipe(_ sender: UISwipeGestureRecognizer)
{
print("swiped")
member?.swipe(direction: sender.direction)
}
}

显然,为了保持这篇文章的重点和易于理解,一些代码被省略了。有趣的是,我有时会调用 swipe 函数,但大多数时候它不会打印“swiped”或调用 member?.swipe。你能给我的任何帮助都会很棒。感谢您考虑此事。

此致,
肖恩

最佳答案

如果没有有效的代码示例,则不清楚其上下文是什么。

您可能会在您想要的 View 之外的另一个 View 中开始滑动,并在您想要的 View 中结束。

请参阅我针对此场景的答案和示例项目:UISwipeGestureRecognizer doesn't recognize swipe gesture initiated outside the view

如果您有其他元素“吃掉”UITouch,例如按钮或其他启用交互的 View ,那就可以解释了。

如果您想调试,请尝试将 UITapGestureRecognizer 添加到您的 View 中,然后使用

    let location = sender.location(ofTouch: 0, in: mysubview)

让您的 subview 查看其是否在 View 边界内。

关于ios - 滑动手势识别器在 SKScene 中间歇性工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40560486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com