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.

Krivvenz
  • 3,911
  • 3
  • 22
  • 32

7 Answers7

3

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

buttton.exclusiveTouch = true
Abhishek
  • 90
  • 4
1

You could write an extension for UIBarButtonItem to add isExclusiveTouch?

AMAN77
  • 6,218
  • 9
  • 45
  • 60
  • 1
    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. – Krivvenz Dec 20 '16 at 13:28
  • 1
    What about writing your own extension for both button types and then you can do a check for either as AnyObjects? – AMAN77 Dec 20 '16 at 13:37
  • 1
    Are you able to provide a code example for this at all please? :). – Krivvenz Dec 20 '16 at 15:09
  • 1
    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 http://stackoverflow.com/questions/28471164/how-to-set-back-button-text-in-swift – AMAN77 Dec 21 '16 at 09:04
  • 1
    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. – Krivvenz Dec 21 '16 at 09:51
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

Aman Gupta
  • 985
  • 1
  • 8
  • 18
  • Hi Aman, All my screens already have Multi Touch turned off... by default I think. It doesn't fix the issue. – Krivvenz Dec 21 '16 at 09:46
0

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

let skView = self.view as! SKView
skView.isMultipleTouchEnabled = false
hoboBob
  • 832
  • 1
  • 17
  • 37
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 :)

0

It's working fine in Swift

self.view.isMultipleTouchEnabled = false
buttonHistory.isExclusiveTouch = true
Srinivasan_iOS
  • 972
  • 10
  • 12
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 }
    }