iPad landscape-only app not responding to touches

2019-05-02 05:34发布

问题:

I’m an experienced developer, but relatively new to iOS.

I’m having some trouble with an iPad App, where my views are not responding to button touches in the bottom third of the screen. Touches on other buttons are working fine, so I know my views are getting hooked up properly when they’re loaded (I’ve created them in IB.) I get the same behavior on both the simulator and the device.

This is a landscape-orientation-only App, and I’m loading views using [NSBundle LoadNibNamed:]. This was the only non-trivial portion of the App, and I think I’ve jumped through all the appropriate hoops:

  • Added Initial Interface Orientation line to my .plist
  • Designed my views in Landscape orientation in IB
  • Added shouldAutoRotateToInterfaceOrientation to my top-level view that only return YES for landscape orientations

The landscape orientation may not be related, but I thought I should mention it, since it was the only thing I found a little wonky to build, and I see from the boards that other people have found this problematic as well..

Does anyone have any ideas?

Thanks.

回答1:

More than likely, your autoresizing masks are not set correctly. This means that the view's bounds are not changing to match the window. Touches are only detected within the bounds of a view's super view, so if you have a button that sits outside its superview's bounds, it won't get any touches.

For a quick test, try setting your view's background color and see if the view does properly extend to the bottom of the screen.



回答2:

It turns out my view's bounds were set to the full screen, but the frame was not. By explicitly setting the frame, I was able to get this working.



回答3:

If your apps, on your app screen, will not respond to touch, just change the orientation. I kept it in landscape mode most of the time, they stopped responding, when I rotated the ipad they started responding right away.