8

我有一个使用整个屏幕的 iPad 应用程序(也就是说,UIStatusBarHidden在 Info.plist 文件中设置为 true)。主窗口和主视图的框架设置为 (0, 0, 768, 1024)。主视图启用了多点触控。

视图控制器有这个代码来处理触摸:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInView:nil];
        NSLog(@"touchesMoved at location %@", NSStringFromCGPoint(location));
    }
}

当我在模拟器中运行该应用程序时,它几乎可以正常工作。当我将鼠标从屏幕的一个边缘移动到另一个边缘时,报告的 X 值从 0 到 767。报告的 Y 值从 20 到 1023。(这是一个已知问题,模拟器不报告顶部的触摸20 像素的屏幕,即使没有状态栏。)

奇怪的是: 当我在实际的 iPad 上运行应用程序时,X 值按预期从 0 变为 767,但报告的 Y 值从 -6 变为 1017,而不是我预期的 0 到 1023。

它似乎在模拟器上正常工作的事实让我怀疑真实设备的触摸屏没有完美校准,而我的只是报告 Y 值偏离了 6 个像素。任何人都可以验证是这种情况吗?否则,还有什么可以解释 Y 值与我预期的相差 6 个像素的原因吗?

(几天后,我应该有第二台 iPad,所以我可以用另一台设备测试它并比较结果。)

4

2 回答 2

1

做一些快速测试,我注意到了同样的事情。我开始了一个基本的基于视图的项目,除了以下代码没有任何改变:

(iPadTestsAppDelegate)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];

    // Override point for customization after app launch    
    viewController.view.multipleTouchEnabled = YES;
    viewController.view.userInteractionEnabled = YES;

    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}

(iPadTestsViewController)

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInView:nil];
        NSLog(@"touchesMoved at location %@", NSStringFromCGPoint(location));
    }
}

当我触摸屏幕边缘时,它会在 x 轴上报告负数,并且在 y 轴上永远不会达到 0。添加一些变量来跟踪 max 和 min 给了我这些作为我们 iPad 的角:{-5, 2}, {758, 2}, {-5, 1019}, {758, 1019}。

于 2010-04-29T17:10:04.427 回答
1

我为不同的 UIInterfaceOrientations 得到不同的值

UIInterfaceOrientation ori = [UIApplication sharedApplication].statusBarOrientation;
CGPoint point = [touch locationInView:self];

鉴于此,我认为这是软件问题,而不是设备问题。

于 2012-08-24T04:15:14.137 回答