TouchMoved and wrong screen range? or Bug in iOS?

前端 未结 3 1871
滥情空心
滥情空心 2021-01-28 13:40

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 i

相关标签:
3条回答
  • 2021-01-28 14:16

    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.

    0 讨论(0)
  • 2021-01-28 14:33

    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));
    }
    
    0 讨论(0)
  • 2021-01-28 14:36

    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.

    0 讨论(0)
提交回复
热议问题