iPad横向检测触摸屏幕左侧部分的触摸功能

时间:2010-11-25 22:55:19

标签: iphone objective-c cocoa-touch ipad uiview

我正在开发一款风景iPhone应用。它在iPhone上运行良好但是当我在iPad或iPad模拟器上运行时,它在处理x方向超过320的触摸时遇到问题。

很多超过320的UIButtons会在按下时突出显示,但不会动作。

当我将其添加到我的超级浏览中时:

- (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);     
}

它永远不会输出大于320的x值。按下的屏幕任何大于320的部分都会为x输出320.

UIViews都以编程方式完成,没有UIViewControllers。我已经将plist设置为在横向和启动它启动它.DidFinishLaunching我用这个旋转视图:

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

感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

我有类似的问题,但我以编程方式创建了Window,View和ViewController(因为它是使用OpenGL ES的游戏)。

问题是我最初使用与视图相同的矩形创建了窗口。要解决它,只需以这种方式制作窗口:

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

和viewController(创建View):

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

希望这有帮助!

答案 1 :(得分:0)

您的一个父视图或窗口没有正确的框架。

由于触摸是从窗口向上评估到您的视图,如果触摸位于您的任何父视图之外,它将停止。

您可以使用以下代码进行调试:

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

这会在你的框架层次中打印帧...检查一个宽度是320像素