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:
But when I try to press test button or status bar I've got wrong touch recognition:
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
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;