Single cap, created through UITapGestureRecognizer, does not work at UIButton
-
I have a button, UI Button. This button doesn't have any exchenes, I want this escene to be used in the processing of the cap. I've created an event of a single slip through UITapGestureRecognizer. When I slip past the button, the event works. When I slip through the button, I see the animation of the wire, but the event works. I also created a double cap, and he's fine.
Question No. 1
What do you do with a single slip? How do you get him to walk through the button?Question No. 2
How am I supposed to get a button on my tab processing? To be more precise, I need to get the text on the button.Here are excerpts from the code:
override func viewDidLoad() { ...
let singleTap = UITapGestureRecognizer(target: self, action: "singleTap:") singleTap.numberOfTapsRequired = 1 singleTap.numberOfTouchesRequired = 1 view.addGestureRecognizer(singleTap) let doubleTap = UITapGestureRecognizer(target: self, action: "doubleTap:") doubleTap.numberOfTapsRequired = 2 doubleTap.numberOfTouchesRequired = 1 view.addGestureRecognizer(doubleTap) singleTap.requireGestureRecognizerToFail(doubleTap) ...
}
func doubleTap(sender: UIGestureRecognizer) {
if sender.state == .Ended {
print("doubleTap")
}
}func singleTap(sender: UIGestureRecognizer) {
if sender.state == .Ended {
print("singleTap")
}
}func addButton(time:String, x:CGFloat, y:CGFloat, width:CGFloat, height:CGFloat, tag: Int) -> UIButton {
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(x, y, width, height)
button.setTitle(time, forState: UIControlState.Normal)
button.tag = tag
self.scrollView.addSubview(button)
return button
}
-
I was helped on the main website: https://stackoverflow.com/questions/34736552/single-tap-created-by-uitapgesturerecognizer-doesnt-work-on-uibutton/34736789#34736789
You should've put hats on the buttons.
let singleTap = UITapGestureRecognizer(target: self, action: "singleTap:") singleTap.numberOfTapsRequired = 1 singleTap.numberOfTouchesRequired = 1 button.addGestureRecognizer(singleTap)