1

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.

Mind Pixel
  • 816
  • 7
  • 16
david
  • 11
  • 2
  • The problem is probably not the button but the toolbar or the main view. The untouchable portion of the button is probably outside the bounds of its superview (at some level up the superview chain). Things outside their superview are visible but not touchable. To confirm this, try setting the `clipsToBounds` of the view, the toolbar, and everything else to YES. You will find that the bottom of the button is now invisible. – matt May 02 '14 at 02:33
  • And this in turn might be because you are not compensating correctly for the fact that all apps are now full-screen apps: the top of the main view is up behind the status bar. – matt May 02 '14 at 02:34
  • But there's another possibility: there's a bug in the system. See my answer here: http://stackoverflow.com/a/23047708/341994 – matt May 02 '14 at 02:40
  • @matt Thanks for your response. I tried setting `clipsToBounds` to YES to everything I could think of (`_button.view`, `toolbar`, `self.view`, `self.navigationController.view`) and it still looks and behaves the same. Does this suggest to you a bug? My initial guess was like your second comment, but I could never figure out how to compensate correctly. – david May 02 '14 at 07:10
  • The symptom of the bug is exactly what you describe: the button is tappable (because it can receive touch up inside) but does not _look_ tapped (because it doesn't respond to touch down). I'm afraid there's nothing much you can do. This is presumably the Control Center edge pan gesture recognizer getting in your way. – matt May 02 '14 at 16:12
  • But please do file a bug report with Apple. – matt May 02 '14 at 16:12

0 Answers0