TouchsBegan stops working when a view moves outside its supervisor

I use [aSubview touchesBegan]to move the position aSubviewon the screen in relation to my supervisor. His supervisor is not much bigger than subview itself. This is pretty easy to do, as the following snippet shows:

    UITouch* touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:[self superview]];
    self.center = touchPoint;

However, as soon as a aSubviewmoves, as soon as any part of it goes beyond its supervisor, touches in this section are no longer recorded. In other words, it touchesBeganno longer works. I want touches to aSubviewbe recorded no matter where he moved relative to his observation.

Any thoughts?
Howard

+5
source share
4 answers

Mcpunky's answer is almost good, but you can NOT make a pointInsidefunction to always return YES. Thus, the view will capture all touches.

Instead, you need to perform a more accurate check:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{

    return CGRectContainsPoint(self.subviewOutsideMe.frame, point) || CGRectContainsPoint(self.bounds, point);

}
+5
source

I just had a problem with the fact that subviews did not receive input because the supervisor simply did not send touch events for subviews that are outside its borders. In addition, it was important to maintain the boundaries of oversight as they were, and it was also impossible to move sublanguages ​​up the hierarchy. What work was the main add-on for me

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 

YES. : , subviews, .

+2

Apple. touchesBegan , w/ , , , subview touchesBegan .

, , , subviews . , - , , , .

+1

, , , , .

Listen to touchsBegan even in the parent. If you get an event, pass it to the childs view by calling it touchhesBegan yourself.

0
source

All Articles