【问题标题】:iPad Landscape trouble detecting touches on lefthand portion of screeniPad 横向检测屏幕左侧触摸时出现故障
【发布时间】:2011-05-15 22:44:31
【问题描述】:

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

许多超过 320 的 UIButton 在按下时会突出显示,但不会执行它们的操作。

当我将此添加到我的超级视图时:

- (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 设置为以横向启动它,并在 applicationDidFinishLaunching 中旋转视图:

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

感谢任何帮助。

【问题讨论】:

  • 您是否将其构建为“通用应用程序”?当您为 iPad 构建它时,您是否首先按照步骤创建 .nib 文件的 iPad 版本?
  • 不,我将其构建为仅适用于 iPhone 的应用程序。
  • window.bounds = CGRectMake(0, 0, 480, 320); 将应用程序的边界设置为 480 和 320。所以我想你不能超出这个范围。

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


【解决方案1】:

我遇到了类似的问题,但我以编程方式创建了所有窗口、视图和 ViewController(因为它是使用 OpenGL ES 的游戏)。

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

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

和 viewController(创建视图):

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

希望这会有所帮助!

【讨论】:

    【解决方案2】:

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

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

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

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

    这将在您的框架层次结构中打印框架...检查一个是否具有 320 像素的宽度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多