这就是我的代码:
UIButton *svObjectButton = [UIButton buttonWithType:UIButtonTypeCustom];
svObjectButton.frame = CGRectMake(0, 0, 100, 100);
[svObjectButton addTarget:self action:@selector(svObjectTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
[svView addSubview:svObjectButton];
UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
removeButton.frame = CGRectMake(0, 0, 20, 20);
[removeButton addTarget:self action:@selector(removeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[svObjectButton addSubview:removeButton];
[svObjectButton bringSubviewToFront:removeButton];
但由于某种原因,对removeButton的所有触摸都会直接到达svObjectButton。
有什么想法吗?
我希望您在另一个大按钮上添加一个小按钮...要实现这一目标,您可以添加 svView 上有一个具有大按钮框架大小的 UIView(例如,buttonView)。之后,您可以在 buttonView(UIview)上添加两个按钮。您必须避免
为什么removeButton必须是svObjectButton的子视图?
我认为问题在于 UIButton 是 UIButton 的子视图。尝试将removeButton 添加到svView 中。