UITapGestureRecognizer *selfViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeSelfView:)]; [self addGestureRecognizer:selfViewTap];//注意同一個點擊手勢不能添加到多個視圖上
selfViewTap.numberOfTapsRequired = 2;//點擊次數
selfViewTap.numberOfTouchesRequired = 2;//手指個數、單擊
- (void)removeSelfView:(UITapGestureRecognizer *)selfTap{ CGPoint selectPoint = [selfTap locationInView:self]; NSLog(@"%@",[NSValue valueWithCGPoint:selectPoint]); //CGRectContainsPoint(CGRect rect, <#CGPoint point#>)判斷某個點是否包含在某個CGRect區域內
if(!CGRectContainsPoint(_bg_imageView.frame, selectPoint)){ [self removeFromSuperview]; } }