问题
My app is only allowable in the landscape orientations, and it launches in landscape. Thus, the top left corner when the iPad is landscape is (0,0), so everything works fine.
However, when I pick up "touchesBegan"...it isn't working properly. Only when I tap on like the right two-thirds of the iPad does it pick up the touches. I know it has something to do with the orientation, because the app is literally just blank screen with a single UIView and nothing else. It is quite simple. There are no other possible problems that would cause this.
To be sepecific, if I print out the x location in the touchesBegan function, and if the iPad is held with the home button on the left, the width is 1024. And 1024-768 is 256. This is exactly the x position where it begins to sense my touches. Anything to the left of x=256 does not sense the touches.
How do I fix this?
回答1:
Check Struts and Springs and make sure that whatever should pick up the touches is covering the whole area and locked to the 4 sides.
回答2:
To do it programmatically,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; [self.view setFrame:CGRectMake(0.0f, 0.0f, appFrame.size.width, appFrame.size.height)]; return YES; // if you want to support only LANDSCAPE mode, use the line below /* return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight); */ }
This sets the view to occupy the full screen.
回答3:
The answer is that, when defining the UIWindow, it needs to be defined as
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
and not strict coordinates.
来源:https://stackoverflow.com/questions/9254136/ipad-landscape-messing-up-touches-began