iOS - Detecting touches in a UIView?

前端 未结 4 564
无人共我
无人共我 2021-01-12 01:55

So I have a Subclass of UIView that is suppose to detect touches. The view detect touches only if the touches started inside the current view. When the touches start outside

4条回答
  •  梦谈多话
    2021-01-12 02:13

    this should fix it:

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        UITouch *touch = [[event allTouches] anyObject];
        for (UIView* subView in self.subviews) 
        {
            if([subView pointInside:[self convertPoint:touch toView:subView] withEvent:event])
            {
                //do your code here
            }
        }
    }
    

提交回复
热议问题