0

I have a UITextFields on the navigationitem custom titleview. When I touch it's out right side, it's get focused too. I test the situation in the hittest method. Here is the data.

hitbounds field point: {269, 6.5}, bounds:{{0, 0}, {255, 35}}; searchView point: {59, 6.5}, bounds: {{0, 0}, {45, 35}}; searchButton: {58, 11}, bounds: {{0, 0}, {44, 44}}

Field view contain a searchview in the right who contain a search button.

field point: {269, 6.5}, bounds:{{0, 0}, {255, 35}};
The point is not in its bounds clearly. But The field get foucsed and the keyboard appears.

And eventually I find when the keyboard appear, the methods even not are called pointInside:(CGPoint)point withEvent:(UIEvent *)event hitTest:(CGPoint)point withEvent:(UIEvent *)event

Why? Thanks.

Victor Choy
  • 4,006
  • 28
  • 35

1 Answers1

0

I got a clue from Why does UINavigationBar steal touch events?

I guess navigation bar steal touch event and dispatch the touch event to textfield directly.

So Here is the solution. It works well.

@implementation UINavigationBar(Xxxxxx)

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *v = [super hitTest:point withEvent:event];
    return v == self ? nil: v;
}

@end
Community
  • 1
  • 1
Victor Choy
  • 4,006
  • 28
  • 35