I have a button, UI Button. This button has no action, I want this action to cause tapa to process. I created a single tap event through the uitapgesturerecognizer. When I bury past the button, the event works. When I taping on the button, I see an animation of the groilt, but the event is triggered. I also created a double tap, everything is fine with him.
question # 1
What to do with solitary tap? How to make it go through the button?
Question # 2
How can I get a button on the Tapa handler on which tap was performed? To be more accurate, I need to know the text on the button.
Here is the excerpt from the code:
override func viewdidload () {
...
Let Singletap = UITAPgestureRecoGnizer (Target: Self, Action: "Singletap:")
Singletap.numberoftapsrequired = 1.
Singletap.numberoftoucksrequired = 1.
View.addgestureRecoGnizer (Singletap)
Let DoubleTap = UITAPgestureReCognizer (Target: Self, Action: "DoubleTap:")
doubletap.numberoftpsrequired = 2.
DoubleTap.numberoftouchesRequired = 1.
View.addgestureRecoGnizer (DoubleTap)
Singletap.RequiregestureRecoGnizertofail (DoubleTap)
...
}
FUNC DOUBLETAP (Sender: UigestureReCognizer) {
if sender.state == .nded {
Print ("DoubleTap")
}
}
Func Singletap (Sender: UigestureReCognizer) {
if sender.state == .nded {
Print ("Singletap")
}
}
Func AddButton (Time: String, X: CGFloat, Y: CGFloat, Width: CGFloat, Height: CGFloat, Tag: Int) - & gt; 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.
}
Answer 1, Authority 100%
I was helped on the main site: https : //stackoverflow.com/questions/34736552/single-tap-created-by-uitapgesturerecognizer-doesnt-work-on-uibutton/34736789#34736789
It was necessary to hang the taps not on the wrist, but on the buttons.
Let Singletap = uitapgesturerecognizer (target: self, action: "singletap:")
Singletap.numberoftapsrequired = 1.
Singletap.numberoftoucksrequired = 1.
Button.addgestureRecoGnizer (Singletap)
Answer 2, Authority 100%
answer to # 2
You can do it in several ways:
-
UIGESTURERECOGNIZER object has the property View
GESTURE RECOGNIZER IS ATTACHED TO.) With which you can
get your own button, well, and gave it to change its text with
Settitle : Forstate: . -
When creating a button to specify TAG , in Hendler will receive this Tag, then logic.