我有个奇怪的问题。我在子视图中添加了一个基本的轻击手势识别器,但仅在喜欢时才起作用。有时,它可以在第二次点击时起作用,有时在第三次甚至更多次点击时起作用。但是,当我向手势识别器调用的功能中添加print("whatever")
时,该功能始终在我第一次单击该子视图时起作用。
我该如何解决?
在这两个示例上出现相同的问题:
SubView:
let getgiftGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(self.getgift))
self.continueButton.addGestureRecognizer(getgiftGestureRecognizer)
DispatchQueue.main.async {
self.coverAnyUIElement(element: self.successView)
let gift = Scnnode()
gift.geometry = SCNBox(width: 1,height: 1,length: 1,chamferRadius: 0)
//nahodne vygenerovat geometry,nebo barvu
let ownedGeometries = UserDefaults.standard.array(forKey: "ownedGeometries")
let ownedColors = UserDefaults.standard.array(forKey: "ownedColors")
let notOwnedGeometriesCount = geometriesCount - ownedGeometries!.count
let notOwnedColorsCount = colorsCount - ownedColors!.count
if notOwnedGeometriesCount == 0{
//mam vsechny geometrie
//vygeneruju barvu
}else if notOwnedColorsCount == 0{
//mam vsechny barvy
//vygeneruju geometrii
}else if(notOwnedGeometriesCount == 0 && notOwnedColorsCount == 0){
//mam uplne vsechno
}else{
//vygeneruj cokoliv
let random = Int.random(in: 0...10)
if random <= 3{
//vygeneruj geometrii
}else{
//vygeneruj barvu
}
}
print(self.generateColor())
print(self.generateGeometry())
self.chest.opacity = 1
self.chest.position.y = -1.8
self.world.addChildNode(self.chest)
let viko = self.chest.childNode(withName: "viko",recursively: false)
self.chest.addChildNode(gift)
print("VLAKNO1: \(Thread.isMainThread)")
viko?.runaction(SCNaction.rotateBy(x: 0,y: 0,z: -90/(180/CGFloat.pi),duration: 1),completionHandler: {
print("VLAKNO2: \(Thread.isMainThread)")
let pohyb = SCNaction.move(by: SCNVector3(0,4,0),duration: 1)
gift.runaction(pohyb,completionHandler: {
print("VLAKNO3: \(Thread.isMainThread)")
self.showConfirmgiftButton()
})
})
}
}
按钮:
confirmgiftButton.addTarget(self,action: #selector(acceptedgift),for: .touchUpInside)
@objc func acceptedgift(){
DispatchQueue.main.async {
UIButton.animate(withDuration: 0.2,animations: {
self.confirmgiftButton.alpha = 0.9
}) { (_) in
UIButton.animate(withDuration: 0.2,animations: {
self.confirmgiftButton.alpha = 1
}) { (_) in
//print("VLAKNO1: \(Thread.isMainThread)")
self.chest.runaction(SCNaction.fadeOut(duration: 0.5),completionHandler: {
// print("Vlakno: \(Thread.isMainThread)")
self.chest.removeFromParentNode()
self.moveToMenu()
})
//print("VLAKNO2: \(Thread.isMainThread)")
self.coverAnyUIElement(element: self.confirmgiftButton)
}
}
}
}