このコードの目的は、UIViewを画面の特定の場所にアニメーション化することです。残念ながら、単にタップを登録していません。デリゲートを私のセットアップで何かに設定すると思いますか?どんな助けもありがとう!UIButton TapGestureRecognizerが起動しない
public class NoteCardView:UIView {
internal var titleLabelTapGestureRecognizer: UITapGestureRecognizer?
@IBInspectable var delegate: NoteCardViewDelegate?
public func setup(positionX:CGFloat, positionY: CGFloat, view: UIView, cardValue: Int) {
self.titleLabelTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(NoteCardView.handleTitleLabelTap(_:)))
self.addGestureRecognizer(titleLabelTapGestureRecognizer!)
}
func handleTitleLabelTap(_ recognizer:UITapGestureRecognizer) {
self.delegate?.noteCardViewTitleLabelDidRecieveTap(self)
}
}
public protocol NoteCardViewDelegate {
func noteCardViewTitleLabelDidRecieveTap(_ view: NoteCardView!) -> Bool
}
extension MainViewController: NoteCardViewDelegate {
func noteCardViewTitleLabelDidRecieveTap(_ view: NoteCardView!) -> Bool {
let card:NoteCardView = (view)
UIView.animate(withDuration: 0.5, delay: 0.0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
card.titleLabel.leftAnchor.constraint(equalTo: card.titleLabel.leftAnchor, constant: (self.elementPlacement/4) + 20)
card.titleLabel.bottomAnchor.constraint(equalTo: card.titleLabel.bottomAnchor, constant: 100)
}, completion: { (finished: Bool) in
self.elementPlacement = (self.elementPlacement + 1)
card.titleLabelTapGestureRecognizer!.isEnabled = !(self.elementPlacement == 5)
})
return true
}
}
'setup'メソッドはどこにありますか? – rmaddy
あなたの質問にはどんなボタンがありますか?ボタンはありません。 – rmaddy
@rmaddyの設定はView ControllerのviewDidLoad()で呼び出されます。また、NoteCardViewにサブビューとしてButtonを追加しています。私は、ボタンまたはノートカードのビューからタップジェスチャ認識機能を作成するかどうか分かりません。 –