diff --git a/CXCardView/CXCardContainerView.m b/CXCardView/CXCardContainerView.m index bbbfcce..6e80a20 100644 --- a/CXCardView/CXCardContainerView.m +++ b/CXCardView/CXCardContainerView.m @@ -168,5 +168,9 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event } } +-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ + [self touchesEnded:touches withEvent:event]; +} + #pragma mark - Private Method @end diff --git a/CXCardView/CXCardView.m b/CXCardView/CXCardView.m index 937f19d..f0d3ffa 100644 --- a/CXCardView/CXCardView.m +++ b/CXCardView/CXCardView.m @@ -94,10 +94,18 @@ - (id)initWithFrame:(CGRect)frame self = [super initWithFrame:frame]; if (self) { // Initialization code + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped:)]; + [self addGestureRecognizer:tap]; } return self; } - +- (void)backgroundTapped:(UITapGestureRecognizer *)tgr{ + CGPoint touchedPoint = [tgr locationInView:self]; + if (!CGRectContainsPoint(self.containerView.frame, touchedPoint)) { + //Dismiss when background is tapped + [self dismiss]; + } +} - (void)setDraggable:(BOOL)draggable { if (_draggable == draggable) {