Reputation: 4617
I have UIBUtton
in UICollectionViewCell
as show in image. I had set touchUpInside Action in xib. I had set background image of button is pink and lable as yellow. UIButton
comes at top of the label. Now the problem is that UIButton
in not getting touch event in pink area it only get touch events on orange area. why it is so.
- (IBAction)checkButtonTap:(id)sender event:(id)event
{
DLog(@"%s",__func__);
}
O a hidden view is overlapping the button due to which it is touch event was not reaching to the button.
Upvotes: 1
Views: 704
Reputation: 2349
Just to be sure I understand your issue, you have your UICollectionView
in yellow and your UIbutton
in pink, correct ?
If so, it seems you want to intercept the touchUpInside event outside your button's superview in yellow. You can look at this answer which deal with kind of problem.
Even if you finally find the solution to your problem, to clarify my answer, if you want to interact with an UIButton
which is not inside its superview's frame, you may need to need to implement the method - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
of the superview (here the UICollectionViewCell
):
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil) {
return result;
}
}
}
return nil;
}
(thanks Noam!)
Upvotes: 1
Reputation: 4617
O sorry, there was hidden view that is overlapping the button due to which touch event was not reaching to the button.
Upvotes: 0
Reputation: 1
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)]; [buttonname addGestureRecognizer:tapGesture]; buttonname.userInteractionEnabled = YES;
Upvotes: 0