3

Summary

I've got wrong UISearchBar touch area after pushing view controller with status bar from view controller without it.

Explanation

I have two view controllers A and B inside UINavigationController. A hides status bar with following code:

- (BOOL)prefersStatusBarHidden {
    return YES;
}

B has UISearchBar inside UINavigationController title view. In this view status bar is enabled:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

Nothing seems to be wrong after push B from A:

enter image description here enter image description here

But when I try to press test button or status bar I've got wrong touch recognition:

enter image description here

Search bar and back button become active when I press on red area under navigation bar.

Video: https://www.youtube.com/watch?v=Jw4kDOFBCIg

Small sample project: https://github.com/leo150/SearchBarTest

Any ideas? Thanks

Leo
  • 3,003
  • 5
  • 38
  • 61
  • must be a bug with the apple. – Teja Nandamuri Dec 07 '15 at 16:51
  • DId you try adding a transparent UIVIEw as a mask to interfere with the touches ? It is a nasty hack to do, but it is worth a try if you think it is a serios bug!!! – Teja Nandamuri Dec 07 '15 at 17:01
  • @Mr.T, thanks for your response. Yes, I'd tried to add `insertSubview: transparentButton aboveSubview: searchBar` without any success. Search bar is clicked through my button. – Leo Dec 07 '15 at 17:06

2 Answers2

1

This is actually a bug or feature of apple's implementation. We always have issues with buttons right under the navigation bar.

Apple probably did it so it's easier to tap the more prominent UI part (navbar).

Alistra
  • 5,177
  • 2
  • 30
  • 42
  • It's always possible to change UI and remove search from nav bar etc. But is here more correct approach? – Leo Dec 14 '15 at 14:09
1

Like Alistra said it's an Apple's implementation for a better UX.

Here is a related thread with some work around: Why does UINavigationBar steal touch events?

And the official answer of an Apple's engineer:

I recommend that you avoid having touch-sensitive UI in such close proximity to the nav bar or toolbar. These areas are typically known as "slop factors" making it easier for users to perform touch events on buttons without the difficulty of performing precision touches. This is also the case for UIButtons for example.

But if you want to capture the touch event before the navigation bar or toolbar receives it, you can subclass UIWindow and override: -(void)sendEvent:(UIEvent *)event;

Community
  • 1
  • 1
Lory Huz
  • 1,557
  • 2
  • 15
  • 23