我有一个较小的UIButton,它位于一个较大的UIButton之上。
现在的问题是,如果我点击较小的UIButton,它也会触发较大的UIButton。我用来确定按钮是否被点击的代码是:
if(CGRectContainsPoint(button1.frame, location)) {
}是否有按钮的属性或某种自动方法来使较小的按钮不影响较大的按钮?
我知道我可以修改上面的代码,如果它在Button1的框架内,而不是在button2内,但有没有其他方法呢?
发布于 2012-01-29 05:31:50
UIControl (它是UIButton的超类)使用操作选择器将自身作为唯一的参数传递给它的目标。使用它,它就是为这些情况准备的!
[smallButton addTarget:self action:@selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];
[bigButton addTarget:self action:@selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];
// ...
- (void) doStuff:(UIButton *)btn
{
if (btn == smallButton)
{
// smaller button was clicked
}
else
{
// bigger button was clicked
}
}https://stackoverflow.com/questions/9048417
复制相似问题