UIButton fails to properly register touch in bottom region of iPhone screen

前端 未结 9 1171
南方客
南方客 2020-11-28 08:49

I have an app with many different buttons arranged in a calculator like, square / rectangular format. It is actually extremely similar to the default iOS calculator. There a

9条回答
  •  执念已碎
    2020-11-28 09:24

    The cause for this issue is that Apple seems to place a GestureRecognizer at the bottom of the screen that delays touches in any other view. After fiddling around with gesture recognizers on the App's windows I came up with a solution that incorporates a subclass of UIButton:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
        BOOL inside = [super pointInside: point withEvent: event];
    
        if (inside && !self.isHighlighted && event.type == UIEventTypeTouches)
        {
            self.highlighted = YES;
        }
    
        return inside;
    }
    

    The given method is getting called although touchesBegan: is called delayed. A check if the view is at the bottom of the screen may be suitable to prevent any side effects that may occur with this fix.

提交回复
热议问题