Search code examples
iosipadios6landscapeuitapgesturerecognizer

UITapGestureRecognizer fails on iPad in landscape orientation


I am working on a single-view app that has a UITapGestureRecognizer. I noticed that when I tried it on my iPad, the taps weren't being recognized. After I zoomed the app with the 1x/2x button, the taps started working. What am I doing wrong?

I have narrowed this down to a very small sample. I started with the XCode "Single View Application", and the following is the viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    info = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 20)];
    [self.view addSubview:info];

    tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [self.view addGestureRecognizer:tapper];
}

Here is what I know so far:

  • Works on iPhone-sized screens.
  • Works on iPad in portrait orientation.
  • Fails on iPad in landscape orientation, until the view is zoomed with 1x/2x, then it starts working (and continues working after zooming back to the original zoom level).
  • Exhibits the same behaviour with the iPad simulator.

The complete code is in a GitHub repository so you can view the whole thing or try it. XCode 4.5.1, iPad retina, iOS 6.0.1.


Solution

  • I have found that if I remove all of the entries under "Supported interface orientation" in the app's plist, this problem goes away. Or if you check the "Hide during application launch" option for the "Status Bar" settings on the Summary screen of the Target settings, this also fixes it:

    hide during application launch

    There's no logical reason that I can see that either of these options should fix this bug, but they both do.

    Obviously, if you do play around with the "Supported interface orientation" option, in iOS 6, you can still programmatically control the permitted orientations via supportedInterfaceOrientations (shouldAutorotateToInterfaceOrientation: in iOS 5).