0
我有一個SKScene,其中有幾個滑動手勢識別器,但滑動手勢很少被識別,我不知道爲什麼。這裏是我的代碼:滑動手勢識別器僅在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。你可以給我的任何幫助都會很棒。感謝您考慮這件事。
真誠,
肖恩
盡我所知,我之所以會出現這個問題,是因爲我在同一個視圖中也有一個平移手勢識別器,即使平移是垂直的而且滑動是水平的。我們通過改變設計來解決問題,以便在底部有響應滑動和敲擊的按鈕。這解決了我們的問題。感謝您提供您的意見。 –