且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

两按钮同时按下输入

更新时间:2023-12-03 20:27:10

由于 UIButton UIControl 的子类,它继承的UIControl的 touchInside 属性。此外,当 UIButton 发送touch-up-inside动作时,它仍会使用 touchInside > YES 。所以你可以只钩住这两个按钮到这个动作:

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];
    }
}

默认情况下,Interface Builder会挂接 - 内部事件当你控制 - 拖动。如果你宁愿在第二个按钮被同时触摸的时刻发射nukes,挂钩触动事件。您可以通过按住Control键点击按钮而不是控件,然后拖动它们来实现。

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.