简体   繁体   中英

In swift, I have a UIButton inside a UIView inside a UIStackView, and the button is not responding

I have a UIButton, for which I have a touchUpInside IBAoutlet function call, and it is embedded inside a view, which is then embedded inside a stackview. I have User Interaction enabled for all three of of the stackview, the view and the button.

However, the touchUpInside function is not called when I click the button. Does anyone know if this has a solution?

The container view for the button is likely shrined to a small size and thus it and its subviews do not receive touches. Subviews are displayed because "Clip to bounds" is false by default for all views. So subviews are drawn even outside the bounds. The easiest way to check is to give a container view a background color. If this is the case, then there are several ways to resolve the issue:

  1. Set a reasonable constraints to the container. Stick to nearest neighbour boundaries, for example. Or set a minimum size.
  2. Set a size for the container view.
  3. If the container view is inside UIStackView you can set Alignment = Fill , (not Center ) which will make the container view take the space suggested by UIStackView.

With the limited context, I can only give a guess. Perhaps something is blocking the button such as another view on top of it? Sometimes the order of things in your storyboard file can make certain things not register touches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM