问题
I found interesting bug in iOS, but trying to belive that i'm wrong. You have to do 2 things:
1) Create single-view template for iOS
2) Write small function in 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
So if u try to move finger on display from screen's top to bottom (portrait mode) - you get points in range [-5.5 .. 469]... i can't explain this, it happens only on device, in simulator it works fine.
SOME DEBUG INFO:
with status bar and NO wantsFullScreenLayout range is: [-25.5 .. 449]
with status bar and YES wantsFullScreenLayout range is: [-5.5 .. 469]
without status bar and NO/YES FullScreenLayout the range is: [-5.5 .. 469]
with status bar and NO wantsFullScreenLayout view.frame is (0, 20, 320, 460) and view.bounds is (0, 0, 320, 460)
with status bar and YES wantsFullScreenLayout view.frame is (0, 0, 320, 480) and view.bounds is (0, 0, 320, 480)
without status bar and NO/YES FullScreenLayout view.frame is (0, 0, 320, 480) and view.bounds is too (0, 0, 320, 480)
Please, help to explain this stuff, it happens only on devices...
回答1:
Because the status bar is out of limits of the view. And you gets negative values when you touch on status bar.
Try this:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
CGPoint point = [touch locationInView:[touch window]];
NSLog(@"%@", NSStringFromCGPoint(point));
}
回答2:
I found this from one of Apple's tutorials on a finger-painting program:
- (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;
}
Looks like you need to convert the touch to OpenGL coordinates to get the result you are expecting. Hope this helps.
回答3:
The view of root viewController always acts like portrait mode. You should insert a new view inside of the root one. And this new view will acts correctly, will give right size and coordinates according to Apple says.
for example ;
UIView *v = self;
while ([[v superview] superview] != NULL) {
v = [v superview];
}
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:v];
touchPoint will be the correct one.
来源:https://stackoverflow.com/questions/13222013/touchmoved-and-wrong-screen-range-or-bug-in-ios