In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces iOS how to achieve irregular Button click effect, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
Problems encountered
The buttons of function 1, 2, 3 and 4 can realize the click function. But at the four corners of the red box, it will also respond to the corresponding click event. When you click on the four corners of the purple box, the response is function 5, not the corresponding function.
Solution idea
Expected result
Find the right Button to handle click events
Problems that need to be understood.
How is the event transmitted? How to judge who will deal with the current event?
How is the event transmitted?
When the user touches the actual screen, a Touch Event is generated and this event is added to the event queue managed by UIApplication. UIApplication sequentially takes events from the event queue and distributes them to the view for processing. When the event is emitted, it starts with keyWindow, passes it up in turn, including Controller and View, and finally finds the appropriate view to respond to the event.
You can see that when an event occurs, the event is passed from the parent control to the child control, that is, UIApplication-> UIWindow-> UIView-> initial view. This is the passing of the event, that is, the process of finding the most appropriate view.
Two methods are involved:
Func hitTest (_ point: CGPoint, with event: UIEvent?)-> UIView?func point (inside point: CGPoint, with event: UIEvent?)-> Bool
When UIApplication sends an event to keyWindow, hitTest is called to find the most appropriate view to handle the event. The logic of judgment is as follows:
First determine whether you are able to respond to touch events (
UserInteractionEnabled==true
、
Hidden==true
、
Alpha Bool method. It determines whether the current event needs to be handled by itself.
Determine whether the point is within the frame range of its own button.imageView. If the color value of the click point in button.imageView is less than the threshold, false is returned.
Thank you for reading this article carefully. I hope the article "how to achieve irregular Button clicks in iOS" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.