How to Disable Multi Touch on UIBarButtonItems & UI Buttons?
Asked Answered
D

7

8

My app has quite a few buttons on each screen as well as a UIBarButtonItem back button and I have problems with people being able to multi click buttons. I need only 1 button to be clickable at a time.

Does anyone know how to make a UIBarButtonItem back button exclusive to touch?

I've managed to disable multi clicking the UIButtons by setting each one's view to isExclusiveTouch = true but this doesn't seem to count for the back button in the navigation bar.

The back button doesn't seem to adhere to isExclusiveTouch.

Does anyone have a simple work around that doesn't involve coding each and every buttons send events?

Many Thanks,

Krivvenz.

Diatessaron answered 21/11, 2016 at 11:1 Comment(0)
D
3

you can enable exclusive touch simply this will stop multiple touch until first touch is not done

buttton.exclusiveTouch = true
Disario answered 21/12, 2016 at 8:44 Comment(0)
I
1

You could write an extension for UIBarButtonItem to add isExclusiveTouch?

Interrupted answered 20/12, 2016 at 12:31 Comment(5)
I don't think that will fix it as the UIBarButtonItem seems to not be "on the same level" as the other buttons. I am wondering though if some sort of protocol or delegate method would work.Diatessaron
What about writing your own extension for both button types and then you can do a check for either as AnyObjects?Interrupted
Are you able to provide a code example for this at all please? :).Diatessaron
Just had another thought, Is it just the back button on the nav bar? Or is it all buttons on the nav bar? Also was trying to code this and noticed that isExclusiveTouch is set on a UIView level which means that it should be accessible to all visible elements(children of UIView) already, just a question of accessing it. Check this out #28471664Interrupted
It can be any button in the nav bar. It's like the nav bar and the ViewController that it is displayed on top of are not directly associated with each other. So if you have multiple buttons in the nav bar and set exclusiveTouch to true it will work but just for those buttons in the navBar. If you set exclusiveTouch on buttons in the ViewController then only the ones in the ViewController will work. They won't work in harmony across the two though.Diatessaron
A
1

you can simply disable the multi-touch property of the super view. You can also find this property in the storyboard.

enter image description here

Azerbaijan answered 21/12, 2016 at 3:36 Comment(1)
Hi Aman, All my screens already have Multi Touch turned off... by default I think. It doesn't fix the issue.Diatessaron
F
0

you could try this for the scene where you want to disable multiple touch.

let skView = self.view as! SKView
skView.isMultipleTouchEnabled = false
Fatidic answered 24/2, 2018 at 18:35 Comment(0)
V
0

I have found a solution to this. isExclusiveTouch is the solution in the end, but the reason why this property didn't do anything is because you need to set it also on all of the subviews of each button that you want to set as isExclusiveTouch = true. Then it works as expected :)

Vacationist answered 15/8, 2019 at 9:20 Comment(0)
B
0

It's working fine in Swift

self.view.isMultipleTouchEnabled = false
buttonHistory.isExclusiveTouch = true
Bookworm answered 6/3, 2020 at 12:59 Comment(0)
S
0

In addition of @Luky Lízal answer, you need pay attention that all subviews of a view you want disable multi-touching (exactly all in hierarchy, actually subviews of subviews) must be set as isExclusiveTouch = true. You can run through all of them recursively like that:

    extension UIView
    {
        func allSubViews() -> [UIView] {
            var all: [UIView] = []
    
            func getSubview(view: UIView) {
                all.append(view)
                guard view.subviews.count > 0 else { return }
                view.subviews.forEach{ getSubview(view: $0) }
            }
            getSubview(view: self)
            return all
        }
    }

// Call this method when all views in your parent view were set
    func disableMultipleTouching() {
        self.isMultipleTouchEnabled = false
        self.allSubViews().forEach { $0.isExclusiveTouch = true }
    }
Shoat answered 23/3, 2021 at 11:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.