1

我的笔尖上有两个相互重叠的按钮。我需要在点击时按下它们,但只有顶部按钮执行其功能。有没有办法让顶部按钮在按下顶部按钮时告诉底部按钮激活。我不认为我可以将按钮合并为一个并使用一个 -(IBAction)buttonName 函数,因为一个按钮比另一个大,所以当按下其中一个按钮时,我并不总是需要同时激活两个按钮。

谢谢!

4

2 回答 2

3

有没有办法让顶部按钮在按下顶部按钮时告诉底部按钮激活。

不是真的,但您可以让顶部按钮的操作调用底部按钮的操作。

这是一种方法:

- (IBAction)actionTop:(id)sender
{
    NSLog(@"The top button was activated.");
    [self actionBottom:self];
}

- (IBAction)actionBottom:(id)sender
{
    NSLog(@"The bottom button was activated.");
}

另一种方法是对两者使用相同的操作,并根据触发该操作的按钮确定要做什么:

- (IBAction)action:(id)sender
{
    // if the top button was tapped, do this part
    if (sender == self.topButton) {
        NSLog(@"The top button was activated.");
    }

    // you want the bottom button to be activated no matter which button was tapped, so
    // no need to check here...
    NSLog(@"The bottom button was activated.");
}

底部按钮是改变显示内容的整个屏幕。顶部按钮播放声音,除了有 4 个顶部按钮播放不同的声音

似乎覆盖整个屏幕的隐形按钮可能是解决问题的错误方法。您可能会考虑使用附加到您的视图的手势识别器来触发更改。您的按钮操作可以调用手势识别器使用的相同方法。

于 2013-08-07T21:15:20.043 回答
2

Since one button is larger than the other, I assume that you would like the smaller button to "bring down" the larger button with it, including the change in the visual state. In cases like that you could send your target button a "tap" programmatically, like this:

- (IBAction)largeButtonClick:(id)sender {
}

- (IBAction)smallButtonClick:(id)sender {
    // Perform the acton specific to only the small button, then call
    [largeButton sendActionsForControlEvents:UIControlEventTouchUpInside];
}
于 2013-08-07T21:22:16.523 回答