开发者

touchesMoved UIView detection

开发者 https://www.devze.com 2023-01-22 18:07 出处:网络
I have 2 uiimageviews foo1,foo2 which are not intersecting each other, and I have 3 functions touchesBegan, touchesMoved, touchesEnded

I have 2 uiimageviews foo1,foo2 which are not intersecting each other, and I have 3 functions touchesBegan, touchesMoved, touchesEnded

- (void) touchesMoved:(NSSet *)开发者_如何学Go touches withEvent:(UIEvent *) event
{
    UITouch *touch = [touches anyObject];

        if (foo1 == [touch view]){
       NSLog(@"foo1");
        }    

        if (foo2 == [touch view]){
       NSLog(@"foo2");
        }    
}

I'm holding touch on foo1 and move my finger to foo2, but from nslog I get foo1 message.

Is there any possibility to determine in touchesMoved function when the touch goes on foo 2?

Thanks


It doesn't work this way by default. Once one view has "captured" a touch (in other words, once it's been hit-tested to be inside that view), the touch will "track" to that view until it is released, even if the touch's location goes outside the bounds of the view.

(My guess is that it may be possible to override this behavior with subtle overriding of the -pointInside:withEvent: and/or -hitTest:withEvent: methods, but I can't tell you how off the top of my head, and I'm actually not sure it's possible with these means.)

0

精彩评论

暂无评论...
验证码 换一张
取 消