1. 程式人生 > >iOS 點選提示框檢視以外的其他地方時隱藏彈框

iOS 點選提示框檢視以外的其他地方時隱藏彈框

// 點選提示框檢視以外的其他地方時隱藏彈框
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    CGPoint point = [[touches anyObject] locationInView:self];
    point = [self.alertView.layer convertPoint:point fromLayer:self.layer];
    if (![self.alertView.layer containsPoint:point]) {
        self.hidden = YES;
    }

}