habilite a interação do usuário alterando o alfa alpha swift
Eu tenho uma visão com a função de toque (a interação do usuário está ativada). Se eu configurá-lo sem alterar o alfa, funciona bem. Mas se eu tentar alterar o alfa dessa visualização com atraso, ele não poderá ser tocado durante esta animação. Alguém poderia ajudar?
Aqui está o meu código:
import UIKit
class ViewController: UIViewController {
var myView = UIView()
var n = 0
override func viewDidLoad() {
super.viewDidLoad()
setView()
changeAlpha()
}
func changeAlpha() {
UIView.animate(withDuration: 5) {
self.myView.alpha = 0.1
}
}
func setView() {
let size = view.frame.width
myView = UIView(frame: CGRect(x: 0, y: 0, width: size/3, height: size/3))
myView.center = view.center
myView.backgroundColor = UIColor.red
view.addSubview(myView)
myView.isUserInteractionEnabled = true
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(gameObjectTapped(_:)))
myView.addGestureRecognizer(tapGestureRecognizer)
}
@objc func gameObjectTapped(_ recognizer:UITapGestureRecognizer) {
print("# tap \(n)")
n+=1
}