IOS uibutton click no response solution
preface
In daily development, we often deal with buttons, but sometimes we encounter a difficult problem, that is, the button does not respond to click events. At this time, we need to check from the following aspects
Reason for button not responding
1. The button is added to a parent view that does not have user interaction enabled, such as uiimageview. In this case, the parent interaction attempted view. Userinteractionenabled = yes
Set to yes to solve the problem
2. The button itself is blocked. When you click, you don't click the button at all, but the view on its upper layer, so naturally it won't respond
Here is a way to see the layer. Click the button in the red box in the figure below to see the UI elements of the current running interface. You can see whether the view blocks the button
3. The frame of the button exceeds the frame of the parent view, which is the most likely to appear. The free of the button must be clicked inside the frame of the parent view to be effective. As shown in the figure below, the area in the red box of the button does not respond.
What to do if you encounter this problem? Please continue to look down
Solve problems beyond the click area
In fact, this situation is likely to happen. Take the chestnut I met: the height of the chat area is less than the height of the keyboard, and the input box is the child view of the chat area. After the keyboard pops up, the input box moves up and exceeds the frame of the parent view. At this time, click the button in the red box to switch the expression, and the keyboard action does not respond.
terms of settlement
Here are two methods. Each time there is a touch action, you will use these two methods
Rewrite method - (uiview *) hittest: (cgpoint) point withevent: (uievent *) event
This is a method in view. The processing flow is as follows
So we can handle it when returning nil, because the button is outside the parent view at this time
At this time, clicking the button outside the area also has an effect
summary
The above is the solution to the non response of IOS uibutton click introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support of programming tips!