点击空白页面 模态消失
-(void)ViewDidLoad {
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss:)];
[self.view addGestureRecognizer:tap];
}
-(void)dismiss:(UITapGestureRecognizer *)tap
{
//获取当前点击的位置的坐标
CGPoint point = [tap locationInView:self.view];
NSLog(@"handleSingleTap!pointx:%f,y:%f",point.x,point.y);
//判断这个坐标点的位置是否在 某个视图的坐标范围内
BOOL isInView = self.view.frame.size.height - self.goodsAttribute.frame.size.height > point.y ? YES :NO;
//如果为真说明点击在这个视图中
if (isInView) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
/********************方法二*****************************/
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
//结束编辑
[self.view endEditing:YES];
//获取当前触摸点的集合
UITouch *touch = [touches anyObject];
//获取当前这个点 在当前视图的位置
CGPoint point = [touch locationInView:self.view];
//判断这个点的位置是否在 某个视图的坐标范围内
BOOL isIn = CGRectContainsPoint(self.typeMsg.frame, point);
if (!isIn) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}