How does UIPanGestureRecognizer become invalid when a UIView is scaled or enlarged?
Analysis:
- Zooming changes the UIview
transform
attribute transform
Changes to the viewframe
transform
The touch control cannot trigger the callback method after the change, so the control is judged not to have been touched.
Solution:
There is an API under UIview that we don’t usually use to determine if a touch point is on a control:
- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event; // default returns YES if point is in bounds
Copy the code
So we can rewrite this method for similar problems:
#pragma mark - touch
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
CGPoint p = [self.superview convertPoint:point fromView:self];
if (CGRectContainsPoint(self.frame, p)) {
return YES;
}
return NO;
}
Copy the code