コードがクラスに分割されているときに、タップジェスチャーを機能させるのに問題があります。私はこれは、すべての以前の一つのファイルに含まれていたし、私は次のコードで間違った何かをしたと仮定して、それがスムーズに働いた:スウィフト:タップジェスチャが認識されない
placeContainerView.userInteractionEnabled = true
let showFullPlaceContainerView = UITapGestureRecognizer(target: self, action: Selector(self.showFullPlaceContainerViewFunction(placeContainerView)))
placeContainerView.addGestureRecognizer(showFullPlaceContainerView)
機能がshowFullContainerViewFunction(placeContainerView)
func showFullPlaceContainerViewFunction(placeContainerView: PlaceContainerView) {
placeContainerView.animateExpandContractContainer()
}
と
func animateExpandContractContainer() {
print("Tap gesture working")
if self.displayingPlaceLabel == false {
print(self.displayingPlaceLabel)
self.displayingPlaceLabel = true
UIView.animateWithDuration(0.4, delay: 0.0, options: [], animations: {
self.center.x += 180
}, completion: nil)
} else {
self.displayingPlaceLabel = false
UIView.animateWithDuration(0.4, delay: 0.0, options: [], animations: {
self.center.x -= 180
}, completion: nil)
}
}
何とかplaceContainerViewがタップを認識しておらず、クリックされたときにprintステートメントが返されません。
アイデア?ご協力いただきありがとうございます!
私はセレクタ '#selector(className.methodNameが)'任意のパラメータを持つべきではないか、しかしわかりません。だから何かが間違っているhttp://stackoverflow.com/questions/32085396/using-parameters-in-action-of-uitapgesturerecognizer-in-swift – impression7vx
あなたのセレクタが間違っていると思います。 'Selector(self.showFullPlaceContainerViewFunction(placeContainerView))'の代わりに '#selector(Classname.showFullPlaceContainerViewFunction(_ :))'にする必要があります。 – RJE
@RJEあなたが言ったように私はそれを置き換えました。私はそれを実行し、 "placeContainerView"をタップしようとすると、animateExpandContractContainerが呼び出された場所でエラーが発生する - スレッド1:EXC_BAD_ACCESS – tryingtolearn