美文网首页
iOS点击viewcontroller任意视图外的区域关闭或隐藏

iOS点击viewcontroller任意视图外的区域关闭或隐藏

作者: Lee坚武 | 来源:发表于2020-08-07 10:02 被阅读0次

    .h文件实现方法

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
    

    .m文件实现方法

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [super touchesBegan:touches withEvent:event];
        CGPoint point = [[touches anyObject] locationInView:self.view];
        point = [self.viewWithInit.layer convertPoint:point fromLayer:self.view.layer];
        if (![self.viewWithInit.layer containsPoint:point]) {
            [self.navigationController.view removeFromSuperview];
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS点击viewcontroller任意视图外的区域关闭或隐藏

          本文链接:https://www.haomeiwen.com/subject/lizxdktx.html