[英]Gesture recogniser not working when added button view to the Label view as subview
我使用堆棧視圖在其中呈現標簽,然后將按鈕添加到相應的標簽,使用目標來處理按鈕被點擊時的事件。 這里,當作為子視圖添加到標簽時,不會調用處理程序
Stackview
label1
button1
label2
button2
label3
button3
用於向labelview添加按鈕的功能
func setButton(count:Int){
for i in 0..<count{
buttons[i].tag = i
buttons[i].addTarget(self, action: #selector(handleDelete(_:)), for: .touchUpInside)
label[i].addSubview(buttons[i])
}
處理器
@objc func handleDelete(_ sender:UIButton){
print(sender.tag)
}
將標簽userInteraction設置為true。
另一個更好的解決方案是在標簽外添加按鈕,因此標簽和按鈕都在容器視圖中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.