iOS UIButton超出父视图无法点击解决方法
有时候父子View的frame超出了父View的范围。这时候UIButton等子view就无法点击了。
以UIButton为例,如果UIButton 是 UIView的子视图,但是UIButton超出了UIView的边界,导致超出的部分无法点击可以用下面的方法来实现UIButton的点击:
- (UIView *)clickTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *result = [super hitTest:point withEvent:event];
CGPoint butttonClickPoint = [self.button convertPoint:point fromView:self];
if ([self.button pointInside:buttonPoint withEvent:event]) {
return self.button;
}
return result;
}