GRiMe2D
GRiMe2D

Reputation: 664

Overriding pressBegan and menu button on tvOS

I have one view controller with many subviews. When one presses Menu button, my app should perform some actions. But if there wasn't any "active" actions, my app should close.

override func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {
    guard let type = presses.first?.type else { return }

    //...

    if falls == true && type == .Menu {
        super.pressesBegan(presses, withEvent: event)
    }
}

At first time, this code works as should. But if I reopen app and press Menu button, app closes, however super function wasn't called.

How should I get rid of that?

Upvotes: 0

Views: 675

Answers (1)

GRiMe2D
GRiMe2D

Reputation: 664

I did a dirty hack:

  1. Removed super call:

    super.pressesBegan(presses, withEvent: event)
    
  2. Call suspend on UIApplication when I need to close the app

    if type == .Menu && falls == true {
        UIApplication.sharedApplication().performSelector(Selector("suspend"))
    }
    

Upvotes: 1

Related Questions