简体   繁体   English

允许用户在非矩形UIView内容之外进行交互

[英]Allow user interaction outside a non rectangular UIView content

On a UIView that shows a circle image (needs to stay interactive), how would you prevent the area out side of the circle from receiving any user interactions, so the other ui under that view will still be active? 在显示圆形图像(需要保持交互)的UIView上,如何防止圆形以外的区域接收到任何用户交互,因此该视图下的其他ui仍将处于活动状态?

i tried masking the UIView with CGPath but that didn't help. 我试图用CGPath屏蔽UIView,但这没有帮助。 在此处输入图片说明

any ideas? 有任何想法吗?

Since a touch event bubble down in the view hierarchy, as a UIView, you can check if a touch event is relevant to you, if it is not just return NO and that event will travel down to the next UIView in the hierarchy 由于触摸事件在视图层次结构中冒泡,因此作为UIView,您可以检查触摸事件是否与您相关,如果不只是返回NO,则该事件将向下传播到层次结构中的下一个UIView

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    for (UIView * view in [self subviews]) {
        if ([view pointInside:[self convertPoint:point toView:view] withEvent:event]) {
            return YES;
        }
    }
    return NO;
}

Don't put any elements that receive UI events outside the circle. 请勿将任何接收UI事件的元素放在圆圈之外。 If this is unavoidable, then just disable all of the elements outside of the circle for as long as you need. 如果这是不可避免的,则只要禁用您需要的时间,就禁用圆以外的所有元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM