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

2020-08-07  本文已影响0人  Lee坚武

.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];
    }
}
上一篇下一篇

猜你喜欢

热点阅读