UITapGestureRecognizer breaks UITableView SelectRowAtIndexPath? - ios

if I add tapgesture on background view then I have to long press for select cell and if I set numberoftaprequired is 2 the it will be work normally but I have to give one functionality on single tap

add cancelsTouchesInView to your tap gesture
let tap = UITapGestureRecognizer(target: self, action: #selector(yourfunction))
tap.cancelsTouchesInView = false
try this

Related

Bringing UIViews to front on tap

https://github.com/raylu135/Views-
I'm working on this project, I'd like to add a function that allows me to bring the tapped view to the front.
After some researches, I tried to add an UITapGestureRecognizer and view.bringSubviewToFront but it didn't work... maybe I'm not doing it the right way, how can I do?
It won't work like in the link.
1, You need to setup the tap gesture recogniser
2, You need to create an #objc function and call this on action.
//paste it into viewDidLoad.
let tap = UITapGestureRecognizer(target: self, action: #selector(tapped))
tap.cancelsTouchesInView = false
//Uncomment next line, if you want more than one tap to activate gesture.
//tap.numberOfTapsRequired = 5
self.view.addGestureRecognizer(tap)
// Create a function
#objc func tapped(){
self.view.bringSubviewToFront(UIViewWhatYouWantToBringToFront)
}

iOS: TapGestureRecognizer in UIView not fired

I have create an date component and have problems with the GestureRecognizer.
First line is a StackView with labels. If I attach a TapGestureRecognizer it is fired on touch. The following Lines are subviews in a Stackview consisting of a label and an image view. I can add the Recognizer to the subview, to the label or the image view. It never gets fired and I made sure that userInteraction is enabled.
What could be the problem?
Here an example how I add the recognizer:
func addTap(){
dayLabel.isUserInteractionEnabled = true
imageView.isUserInteractionEnabled = true
isUserInteractionEnabled = true
tap1 = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
tap2 = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
tap3 = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
dayLabel.addGestureRecognizer(tap1!)
imageView.addGestureRecognizer(tap2!)
addGestureRecognizer(tap3!)
}
#objc func handleTap(recognizer: UITapGestureRecognizer){
logger.debug("tap")
changeSelection()
}
You can find a little demo project boiled down to the problem here: https://github.com/ogezue/datedemo
Problem I can see is your view must be cover with Image and label
and you are adding same UITapGestureRecognizer to all so that is added on last object say view (which is covered with image and label) so it may not able to get tap event
You need three different objects of UITapGestureRecognizer you can't add same tap gesture on different views
Hope it may solve your problem
For every view (Label/Imageview) you should create a tap object not the same one added to both . . .

Swift 3 multiple gestureRecorgnizer SWRevealController

I have two gestureRecognizer I want to use.
1) Tap to close side menu (SWRevealController)
2) Tap view to dismiss keyboard
override func viewDidLoad() {
super.viewDidLoad()
menuBtn.addTarget(self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), for: .touchUpInside)
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginController.dismissKeyboard))
self.view.addGestureRecognizer(tap)
}
Having both of these lines together, the dismiss keyboard gestureRecognizer trumps the revealViewController. How can I combine this this use both gestures together?
Make condition in LoginController.dismissKeyboard method.
check if isKeyboard is open, then close it. Otherwise close the (SWRevealController) sidemenu.
For check keyboard is open or not you can use post notification of UIKeyboardWillShowNotification and UIKeyboardWillHideNotification methods.

Add single, double and triple tap gestures to all "buttons" in custom keyboard in swift

I'm trying to create a keyboard the allows single tap, double tap, and triple tap. So I want to add a UITapGestureRecognizer() to each button in my keyboard. I know how to do this manually from the xib file (add each letter it's own gesture, which would take ages) but not quite sure how to do it in the Controller.
I wrote this for double tap in the viewDidLoad() method:
let doubleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "doubleTapCharacter:")
doubleTap.numberOfTapsRequired = 2
for button in self.view.subviews{
button.addGestureRecognizer(doubleTap)
}
and created a doubleTapCharacter() method but it's still not working. I also want to be able to send information to the doubleTapCharacter method.
Any help would be much appreciated. Also, I'm very new to swift so if the instructions are complicated, I'd highly appreciate it if you can break it down a little.
create and add the gesture recognizers:
for button in view.subviews {
// create the gesture recognizer
let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "doubleTapCharacter:")
doubleTapRecognizer.numberOfTapsRequired = 2
// add gesture recognizer to button
button.addGestureRecognizer(doubleTapRecognizer)
}
then implement the target method:
func doubleTapCharacter(doubleTapRecognizer: UITapGestureRecognizer) {
let tappedButton = doubleTapRecognizer.view as! UIButton
print(tappedButton.titleForState(UIControlState.Normal))
}

Double tap gesture on parent view and single tap gesture on child view

I have a double tap UITapGestureRecognizer on a view and a single tap UITapGestureRecognizer on it's child view.
let parentGR = UITapGestureRecognizer(target: self, action: "doubleTappedParent")
parentGR.numberOfTapsRequired = 2
parentView.addGestureRecognizer(parentGR)
let childGR = UITapGestureRecognizer(target: self, action: "singleTappedChild")
childGR.numberOfTapsRequired = 1
childView.addGestureRecognizer(childGR)
When I double tap the child view, both actions are triggered. How can I have it such that the single tap gesture "cancels" the double tap gesture?
Create a relationship between recognizers using requireGestureRecognizerToFail. For instance:
gr2.requireGestureRecognizerToFail(gr)
Update: as #tumber033 mentioned in the comment, in his example gr2 and gr should be swapped, so that there should be
parentGR.requireGestureRecognizerToFail(childGR)

Resources