UITapGestureRecognizer on UITableview's background view not working - ios

I have created a UIView and attached a UITapGestureRecognizer. I've set the view as the target of the UITapGestureRecognizer. I've then set the view as the background view of my table view. The problem is the UITapGestureRecognizer never seems to fire, even when there are no rows in my table view. Any suggestions?
Thanks.

I think no need to create a custom view with the gesture recognizer and setting it as the backgroundView for the tableView .It is better to use a Tap Gesture Recognizer with the table view it self. Like following
Here the tap gesture recognizer is connected with the table view and on tapping the table view or table view cell the event connected with the gesture recognizer getting fired(here the event is tableViewTapped: ).
Unmark the Canceled in View check box of the tap gesture recognizer(in right panel as in the screenshot) to enable single tap selection of the table view cell.

Related

Touch events in a UICustomview is not working - UICustomview

i created a custom view
i had an another view in a viewcontroller which is stackview act as a parent view for customview.
when i displaying view dynamically to that stackview(parent view). view is appearing but Button touch events are not recognizing.
when i displaying customview in a superview - button events are working.
i checked all views userinteraction enable is true.
i dont have any idea whats going on.
any solution

Add scroll controller to CollectionView

I have a Collection View in a ViewController, with a Pan Gesture Recognizer that manages the reordering of the cells. Because of that to scroll the Collection View I want to add a "scroll controller" on the side of the Collection View, like Noteshelf app, as showing here:
My Collection view is a simple collection view with a label for every cell:
Put your note view in a scrollview and disable user scrolling by setting isScrollEnabled to false. Add a UIPanGestureRecognizer to your side bar and make yourself the target of the gesture recognizer. In your tap gesture handler function you:
Get the current translation of the pan with translation(in:)
Use this value to scroll the scrollView with setContentOffset(_:animated:)
reset the translation so you get only the difference and not the total on the next call with setTranslation(_:in:)
Edit to clairfy, UICollectionView inherits from UIScrollView so it has all of the UIScrollView properties, you just need to look under UISCrollView and not UICollectionView.

How to pass a tap to view depending on if dragging/scrolling or just tapping

I have a UIScrollView with another view behind it that has buttons. The buttons cannot be on the scroll view, they must be behind it. I am using the pointInside method to pass taps to the buttons view behind the scroll view if that is where the user is tapping. However, I don't want to pass the tap to the buttons view if the user is trying to drag/scroll. If that is the case I want it to scroll the scroll view instead of pass a tap to the buttons.
How can I accomplish this?
UIScrollView has a panGestureRecognizer property. Use the pan gesture's state to determine if you have to pass touches to your button or not.

UITapGestureRecognizer for UIView in Scroll View doesn't work

I have a uiView with added TapGestureRecognizer. This view is showed in scroll view. If the view is visible on the start, when ViewController with scroll view show, everythink is OK.
Problem occurs when the view is not visible on start (when I need scroll ScrollView to see it) then TapGestureRecognizer doesn't call Tap action.
Did you know how to resolve this problem?
As said by wain
The scroll view also has a gesture recogniser. By default, only 1
gesture recognizer can be handling touches at any one time. You need
to make yourself the delegate of your gesture and then implement
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
to return YES. This will allow it to work at the same time as the
scroll view.
For more detail check Apple's Document link
UIGestureRecognizerDelegate_Protocol
and you can also take reference as Example from below link.
Simultaneous gesture recognizers in Iphone SDK
I hope it will be helpful for you.

ios swipe gesture not being recognized on subview with gesture on parent view

I have a tableview that holds a number of cells with an image centered in each cell. I set a right swipe gesture on the tabelview. Each image view overrides the touches* methods. I noticed that if I right swipe outside the images, the parent view responds. If I swipe over the image views in the cells, the parent does not respond.
Does the swipe gesture get blocked by the touches* override in the child image subviews?
You may add UIswipeguesture to your image subview. So you don't need to override any touch function
Uiswipeguesture gues=uiswipeguestu
Imageview addguesture: gues;

Resources