My app consists of a deck of cards. Most cards in the deck are made in draggableView. I'm trying to make it so that a double tap on the screen will make my buttons on the card disappear/reappear. After reading this post, I tried to give it shot. I put a UITapGesture into my initWithFrame method in my draggableView class, like so:
- (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
[self addSubviewFromNib];
[self setupView];
panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(beingDragged:)];
cardWidth = frame.size.width;
cardHeight = frame.size.height;
type = 0;
panGestureRecognizer.delegate = self;
panGestureRecognizer.cancelsTouchesInView = NO;
_backgroundScrollView.panGestureRecognizer.cancelsTouchesInView = NO;
//...more code above....
_backgroundScrollView.userInteractionEnabled = YES;
tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:_backgroundScrollView action:@selector(doubleTap)];
tapGestureRecognizer.delegate = _backgroundScrollView;
tapGestureRecognizer.numberOfTapsRequired = 2;
[_backgroundScrollView addGestureRecognizer:tapGestureRecognizer];
[self addGestureRecognizer:panGestureRecognizer];
}
- (void) doubleTap: (UITapGestureRecognizer *)tapGesturerecognizer{
_mapButton.hidden = !_mapButton.hidden;
_menuButton.hidden = !_menuButton.hidden;
_phoneButton.hidden = !_phoneButton.hidden;
reviewButton.hidden = !reviewButton.hidden;
_shareButton.hidden = !_shareButton.hidden;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
// If the gesture recognizer is a UITapGestureRecongizer, but the other
// gesture detected is a UIPanGestureRecognizer, require the
// UITapGestureRecognizer to fail.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] &&
[otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
return YES;
} else {
return NO;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
return YES;
}
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint velocity = [panGesture velocityInView:self];
return fabs(velocity.y) <= fabs(velocity.x);
}
return YES;
}
However, if I double tap, I get this sib abrt error:
-[UITapGestureRecognizer velocityInView:]: unrecognized selector sent to instance 0x7f9f9a244230
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapGestureRecognizer velocityInView:]: unrecognized selector sent to instance 0x7f9f9a244230'
I'm assuming this means there's an error between the PanGestureRecognizer and the TapGesture Recognizer. How do I resolve it?
EDIT: Still unresolved, but if I change the tapGesture to be added to draggable view(thus, self), rather than _backgroundScrollView, I get this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DraggableView doubleTap]: unrecognized selector sent to instance 0x7fefdd9e4f70'
OTHER EDIT: I changed it back to backgroundScrollView, and I now get this as the error:
[UIScrollView doubleTap]: unrecognized selector sent to instance 0x7fe5130af000