I am trying to add a button on the toolbar of a UINavigationController that responds to UIControlEventTouchDown. In particular, when the user holds down the button, I want it to continue to fire.
I am noticing that in iOS 7 (this was not a problem in iOS 5 or 6), when the status bar is visible, it is almost as if there is about 20 pixels at the bottom of the screen that no longer respond to UIControlEventTouchDown (i.e., just enough to cover the bottom half of a button placed on the toolbar. Although the button does respond to UIControlEventTouchUpInside in this portion of the screen. The top half of the button still responds to UIControlEventTouchDown.
In other words, when the status bar is present, if you tap the top half of the button, it responds to both events separately, as desired. But if you tap the bottom half of the button, it responds to both events only after UIControlEventTouchUpInside occurs.
When the status bar is hidden, everything works perfectly.
Here is the relevant code from the root view controller of the UINavigationController:
- (BOOL)prefersStatusBarHidden
{
return NO; // if YES, everything works great!
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
_button.backgroundColor = [UIColor redColor];
[_button addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];
[_button addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpInside];
_barButtonItem.customView = _button;
}
- (void)touchDown
{
_button.backgroundColor = [UIColor greenColor];
}
- (void)touchUp
{
_button.backgroundColor = [UIColor redColor];
}
I know that iOS 7 introduced transparent status bars/navigationBars/toolbars which has all sorts of implications when displaying content, but I can't find anything that would help resolve the issue I described above.
I should also add that everything works fine in the simulator. It is only when testing on a device that this problem occurs.
Any suggestions would be greatly appreciated. Thank you.