I have two UIViews. On second "UIView" I have one UIButton, but it must be over the both views. When I click lower middle UIButton - event is fire, but when I click above the middle - nothing works.
How to fix it?
将按钮移至两个视图之外并垂直居中
You should create a subclass of UIView
for UIView2
and override hitTest
like this:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil) {
return result;
}
}
}
return nil;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.