Swift, Custom UIButton does not work when click

最后都变了- 提交于 2019-12-04 06:46:37

I think this is caused because you're adding a couple of UIViews subviews to your current UIButton with userInteractionEnabled, which means that they're handling the user input.

If you do:

view.isUserInteractionEnabled = false

The RoundBtn itself will get all the touch events, instead of this UIViews that you have on top.

Referring to @fdiaz's answer. Swift 4 notation.

Conversely, if you attach some UIButton (or user interactive view) to an UIImageView, you must turn its isUserInteractionEnabled = true to let the touches go through the hierarchy up down to the UIButton.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!