自定义选择器ActionSheet,效果如下
2.gif
弹窗中的蒙层上面加手势收起弹窗,结果导致tableView上面的cell的点击事件无法响应。原因是给一个view上面添加手势,则手势的cancelsTouchesInView属性默认为YES,会阻断view上面的点击事件。解决办法是将cancelsTouchesInView置为NO。
0.gif
Summary
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
Declaration
@property(nonatomic) BOOL cancelsTouchesInView;
Discussion
When this property is YES (the default) and the receiver recognizes its gesture,
the touches of that gesture that are pending are not delivered to the view and
previously delivered touches are cancelled through a touchesCancelled:withEvent:
message sent to the view. If a gesture recognizer doesn’t recognize its gesture
or if the value of this property is NO, the view receives all touches in the
multi-touch sequence.
默认是YES,手势识别器识别到touch之后,会发送touchesCancelled:withEvent: 给你触摸的view,就不会响应点击事件了,只有手势识别器响应touch。
self.userInteractionEnabled = YES;
UITapGestureRecognizer *pan = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissContactView:)];
//防止cell上面点击事件失效
pan.cancelsTouchesInView = NO;
[self addGestureRecognizer:pan];
-(void)dismissContactView:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded){
CGPoint location = [sender locationInView:nil];
if (![self.bottomView pointInside:[self.bottomView convertPoint:location fromView:self] withEvent:nil]){
[self removeGestureRecognizer:sender];
[self p_DCHidenAnimation];
}
}
}