On the problem of iOS gesture response
problem description:
as shown in the figure, I encountered a problem when I was developing a reader project. I needed to pop up a menu when I clicked on the red area, so I added a View in that area. However, when I was sliding in this area, the sliding gesture was blocked by the red area, and the gesture could not be passed to the View of UIPageViewController below.
I want to be able to make this area respond only to click events and ignore sliding gestures. What should I do?
simple version: two steps
pass the response of the pop-up window to the content view of PagedController
by passing the chain.
class RedView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let controller = self.next?.next as! BaseViewController
return controller.children[0].view
}
}
then, calculate the coordinates in the content view and handle the event
class ViewController: UIPageViewController {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let point = touch.location(in:view)
let contentRect = CGRect(origin: CGPoint(x: 100, y: 100), size: CGSize(width: 200, height: 200))
if contentRect.contains(point){
print("")
}
}
}
}
simple version code: https://gitee.com/dengshaoxia...
< hr >
< hr >
< hr >
because it is a menu, in order to avoid a lot of mathematical calculation, in order to avoid doing mobile phone adaptation
under the menu, the top level of the view of PagedController adds a similar transparent menu, with the same coordinates and size.
then overrides the hitTest of each button on the menu, giving its responder to the transparent menu below.
one-to-one correspondence.
this is convenient.
you just need to build the same structure and rewrite the hitTest method.
touchesBegan, there is no need to rewrite this.
< hr >
< hr >
< hr >
< hr >
< hr >
< hr >
The problem you mentioned does not exist. The
system is implemented by default.
For more information, see demo:
https://gitee.com/dengshaoxia....