Two button simultaneous press input

后端 未结 1 1313
一生所求
一生所求 2020-12-11 11:25

I\'m trying to put two buttons on the screen and set them up so that the user needs to press them both at the same time in order to trigger an action.

This is simila

相关标签:
1条回答
  • 2020-12-11 11:33

    Since UIButton is a subclass of UIControl, it inherits the touchInside property of UIControl. Furthermore, when UIButton sends the touch-up-inside action, it still responds to touchInside with YES. So you can just hook both buttons up to this action:

    - (IBAction)buttonWasTouched:(id)sender {
        if (self.button1.touchInside && self.button2.touchInside) {
            [self launchNukes];
        }
    }
    

    By default, Interface Builder hooks up the touch-up-inside event when you control-drag. If you would rather launch the nukes the moment the second button is simultaneously touched, hook up the touch-down events. You do this by control-clicking the buttons instead of control-dragging them.

    0 讨论(0)
提交回复
热议问题