3

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?

CodeGuy
  • 28,427
  • 76
  • 200
  • 317

3 Answers3

2

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.

enter image description here

NJones
  • 27,139
  • 8
  • 70
  • 88
Fernando Madruga
  • 1,746
  • 13
  • 11
  • I'm not familiar with these words. Can you clarify and specify? – CodeGuy Feb 13 '12 at 00:32
  • my app is done programatically without xib...can you show me programatically how to do this? – CodeGuy Feb 13 '12 at 00:43
  • (Thanks NJones for the image). Expanding on Neo's answer: if the device is already in the desired orientation when the app launches it will not call that function so maybe the best place to add the resizing code will probably be viewWillAppear. – Fernando Madruga Feb 13 '12 at 01:09
  • Yeah, what Fernando said is true. Like I mentioned in my other comment, you can place that appFrame and the other line [self.view setFrame:] in viewWillAppear. – Neo Feb 13 '12 at 01:14
  • I did that in viewWillAppear as well. It still thinks the width is 768 and the height is 1024...which is backwards. – CodeGuy Feb 13 '12 at 01:18
  • Are you sure you're allowing only landscape and not portrait instead? How did you set it to allow only landscape? – Fernando Madruga Feb 13 '12 at 01:23
  • I went in and defined "Supported interface orientations (iPad)" – CodeGuy Feb 13 '12 at 01:27
  • The code equivalent of autoresizing in IB (pictured) is `self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;` – NJones Feb 13 '12 at 03:11
  • @CodeGuy If your instantiating without a xib then what does your implementation of loadView look like? – NJones Feb 13 '12 at 04:00
0

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.

Neo
  • 1,554
  • 2
  • 15
  • 28
  • it still does not think i'm touching the screen in landscape mode, as I described above in my question – CodeGuy Feb 13 '12 at 00:56
  • 1
    Of course, you can set the frame anywhere you want (view init or elsewhere before the view is actually displayed)! I was just giving an example which supports multiple orientations. :) – Neo Feb 13 '12 at 00:56
  • so then how do I define the "touchable" area...because it is operating as if I'm in portrait mode, however the graphics are operating in landscape mode – CodeGuy Feb 13 '12 at 00:57
  • @CodeGuy I just implemented a small sample project and it works just fine for me!
    - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        for (UITouch * touch in touches) {
            NSLog(@"%f; %f", [touch locationInView:self.view].x, [touch locationInView:self.view].y);
        }
    }
    
    – Neo Feb 13 '12 at 01:09
  • can you post code for all the code of the project? because it's still not working for me – CodeGuy Feb 13 '12 at 01:13
  • when I print self.view in that function you posted...it gives the wrong frame coordinates – CodeGuy Feb 13 '12 at 01:16
  • I don't understand about what you mean by "wrong frame coordinates". http://pastebin.com/h7fXRhim (SampleController.m); http://pastebin.com/nbfKPQ2g (SampleController.h); – Neo Feb 13 '12 at 01:23
  • I just have what I posted in the answer. So I don't even see the point of pasting the code. :) – Neo Feb 13 '12 at 01:24
  • I think it's best that you paste your code, if it still doesn't work for you. I really am unable to think of what might be going wrong with your code. – Neo Feb 13 '12 at 01:26
  • The point is that giving me 3 lines of code is not a project. Can you give me the whole project? Because clearly, I have used your code, and it is not working. The original problem still exists. Please read my question careuflly. – CodeGuy Feb 13 '12 at 01:26
  • lol.. there is NOTHING ELSE in my project! Like I said, it was a small sample I created JUST now. Anyway, I am sick of trying to answer your question without even seeing what code you wrote. All the best! Let the world know what went wrong. Maybe it will help someone else later. – Neo Feb 13 '12 at 01:29
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7594/discussion-between-neo-and-codeguy) – Neo Feb 13 '12 at 01:32
  • oh, so you make a project with one function, no class variables, no app delegate, etc?!?!??!?!?!? – CodeGuy Feb 13 '12 at 01:34
  • I don't even know why I am responding to this chap.. God help me.. http://www.filefactory.com/file/c2771fb/n/Sample.zip – Neo Feb 13 '12 at 01:35
-1

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.

CodeGuy
  • 28,427
  • 76
  • 200
  • 317