gpt4 book ai didi

ios - UIButton TapGestureRecognizer 未触发

转载 作者:可可西里 更新时间:2023-11-01 02:05:26 25 4
gpt4 key购买 nike

这段代码的目的是将 UIView 动画到屏幕上的某个位置。不幸的是,它根本没有注册水龙头。我是否应该将委托(delegate)设置为我的设置中的某些内容?任何帮助将不胜感激!

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
}
}

最佳答案

您应该在您的 View 中启用 userInteraction。

view.isUserInteractionEnabled = true

关于ios - UIButton TapGestureRecognizer 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43171676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com