私は以下のコードを持っていますが、私が試したすべてのもののほかに、スウィープアップストップではジェスチャは認識されません(コンソールにはスワイプされません)。どうしたらいいですか、ありがとう!UIImageViewのスワイプスワイプジェスチャーが全く機能していません
私はviewDidLoad関数にsetupInputComponents()を持っており、正しく呼び出されています。
func setupInputComponents() {
let containerView = UIView()
view.addSubview(containerView)
let swipeUpDots = UIImageView()
swipeUpDots.image = #imageLiteral(resourceName: "threeDots")
swipeUpDots.contentMode = .scaleAspectFit
containerView.addSubview(swipeUpDots)
// Adding swipe functionality
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(getSwipedUp(swipeGestureRecognizer:)))
swipeUpDots.addGestureRecognizer(swipeUp)
swipeUpDots.isUserInteractionEnabled = true
}
@objc func getSwipedUp(swipeGestureRecognizer: UISwipeGestureRecognizer){
print("swiped")
if swipeGestureRecognizer.direction == .up {
print("Up Swiped")
// Send Message
}
}
*全く*を、あなたは* * 'UIView'を初期化するよりも、より多くの何もする必要はありません自動レイアウトを使用している場合。 (その場合、ビューの 'translateAutoresizingMaskIntoConstraints'を' false'に設定する必要があります) – dfd
OPが自動レイアウトを使用しているかどうかはわかりませんでした。しかし、私のためにそれをクリアしてくれてありがとう! –