Selection not working Collection view embedded in container view

533 views Asked by At

I have a container view at the bottom of the screen which overlay on top of the main view. A Collection view is embedded in the container which hidden when the view first load. On the main view controller, I have a tap gesture IBaction which unhide/hide the container view when the main view is tapped.

I have another tap gesture IBaction on the imageView in the collection view. I want to load new content in the main view when the collection view cell(image) is tapped.

My problem is the collectionview(container) is hidden again when I tap on the collection view image. It appears to me that the tap gesture on the main view has priority over the tap gesture on the collection view. I have also tried didselecteditematindexpath instead of tap gesture on the collection view controller but it also does not work. I only want the container to be hidden if I tap anywhere on the main view but not the container/collection view. I am at a lost, please help.

I want to mention that swiping the collection view is working fine without additional coding.

3

There are 3 answers

0
Saurabh Prajapati On BEST ANSWER

Check for Imageview's Property userInteractionEnabled

 containerView.tag = 1234;
 -(IBAction)handleTap:(UITapGestureRecognizer*)recognizer
 {
      if(recognizer.view.tag != 1234)
      {
           //hide container view
      }
 }
0
Ankit Sachan On

Instead of relying on tap gesture for collection view go for delegate Method didSelectItem

0
Yagnesh Dobariya On
give tag to the imageView like 1001

and in handleTap you can check like

if(sender.tag==1001){
NSLog(@"Image Tapped");
}
else{
NSLog(@"Other area of view tapped");
}