TouchMoved和错误的屏幕范围? 还是iOS中的Bug?
我在iOS中发现了有趣的错误,但试图相信我错了。 你必须做两件事:
1)为iOS创建单视图模板
2)在ViewController.m中编写小函数:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; CGPoint point = [touch locationInView:[touch view]]; NSLog(@"%@", NSStringFromCGPoint(point)); }// so u can detect points of your touch
因此,如果你试图从屏幕的上到下移动手指(纵向模式) – 你得到的范围[-5.5 .. 469] …我无法解释这一点,它只发生在设备上,在模拟器中它工作正常。
一些调查信息:
状态栏和NO wantFullScreenLayout范围是:[ – 25.5 .. 449]
状态栏和YES wantFullScreenLayout范围是:[ – 5.5 .. 469]
没有状态栏和NO / YES FullScreenLayout范围是:[ – 5.5 .. 469]
状态栏和NO wantFullScreenLayout view.frame是(0,20,320,460)和view.bounds是(0,0,320,460)
状态栏和YES wantFullScreenLayout view.frame是(0,0,320,480)和view.bounds是(0,0,320,480)
没有状态栏和NO / YES FullScreenLayout view.frame是(0,0,320,480)和view.bounds也是(0,0,320,480)
请帮助解释这些东西,它只发生在设备上……
因为状态栏超出了视图的限制。 当您触摸状态栏时,您会得到负值。
尝试这个:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; CGPoint point = [touch locationInView:[touch window]]; NSLog(@"%@", NSStringFromCGPoint(point)); }
我从Apple的一个关于手指绘画程序的教程中找到了这个:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGRect bounds = [self bounds]; UITouch* touch = [[event touchesForView:self] anyObject]; firstTouch = YES; // Convert touch point from UIView referential to OpenGL one (upside-down flip) location = [touch locationInView:self]; location.y = bounds.size.height - location.y; }
看起来您需要将触摸转换为OpenGL坐标以获得您期望的结果。 希望这可以帮助。
根视图控制器的视图始终像纵向模式一样。 您应该在根目录中插入新视图。 根据Apple的说法,这个新视图将正确运行,将提供正确的尺寸和坐标。
例如 ;
UIView *v = self; while ([[v superview] superview] != NULL) { v = [v superview]; } UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:v];
touchPoint将是正确的。