UIButton in Swift is not registering touches

后端 未结 18 891
情深已故
情深已故 2020-12-29 21:11

I\'m trying to create a UIButton using Swift. It compiles fine and I can see my button in the simulator, but when I click it, nothing happens. This is the code I am using:

18条回答
  •  一向
    一向 (楼主)
    2020-12-29 21:33

    I have had this problem when parent view of my button has isUserInteractionEnabled == false. All subviews will have the same userInteraction as their parent view. So I have just added this line parentView.isUserInteractionEnabled = true and the problem disappeared. Hope this helps someone.

提交回复
热议问题