0

I am working on a landscape iPhone app. It runs fine on the iPhone but when I run it on an iPad or the iPad simulator it has problems dealing with touches that exceed 320 in the x direction.

A lot of the UIButtons beyond 320 will highlight when pressed but won't do their action.

When I add this to my superviews:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
 UITouch *touch = [touches anyObject];

 CGPoint touchLocation = [touch locationInView:self];
 NSLog(@"bounds: %1.2f %1.2f  touch: %1.2f %1.2f",self.bounds.size.width,self.bounds.size.height,touchLocation.x,touchLocation.y);     
}

it will never output an x value greater than 320. Any part of the screen pressed that is greater than 320 gives an output of 320 for x.

The UIViews are all done programatically and without UIViewControllers. I have set the plist to start it in landscape and in the applicationDidFinishLaunching I rotate the views with this:

window.transform = CGAffineTransformMakeRotation((M_PI / 2.0));
window.bounds = CGRectMake(0, 0, 480, 320); 
window.center = CGPointMake(160.0f, 240.0f);
[window makeKeyAndVisible];

Any help is appreciated.

3
  • Are you building this as a "Universal App?" When you built it for iPad, did you first follow the steps to create an iPad version of your .nib files? Nov 26, 2010 at 3:35
  • No, I am building it as an iPhone only app.
    – Jamvert
    Nov 26, 2010 at 18:06
  • window.bounds = CGRectMake(0, 0, 480, 320); sets the bounds for the app as 480 and 320. So i guess you cant get touches beyond this.
    – visakh7
    Jul 21, 2011 at 12:27

2 Answers 2

1

I had a similar problem but I create all programmatically Window, View and ViewController (because it was a game using OpenGL ES).

The problem was that I originally created the window with the same rect as the view. To solve it just make the window in this way:

// Always create the window in Portrait mode
mpWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

and the viewController (who creates the View):

mpController = [[OViewController alloc] initWithFrame: CGRectMake(mPosX, mPosY, mWidth, mHeight)];
// After this line the view will rotate to landscape
[mpWindow addSubview:mpController.view];

Hope this helps!

0

One of your parent views or the window has not the correct frame.

Since touches are evaluated from window upwards to your view it will stop if the touch is outside of any of your views parents.

you could debug it with code like:

UIView *parent = self ;
while (parent = [parent superview]) NSLog("parent: %@",NSStringFromCGRect(parent.frame));

this will print the frames in your frame hierachy ... check if one has a width of 320 pixel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.