UIButton 未接收点击

问题描述 投票:0回答:2

这就是我的代码:

    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。

有什么想法吗?

iphone objective-c cocoa-touch uibutton
2个回答
1
投票

我希望您在另一个大按钮上添加一个小按钮...要实现这一目标,您可以添加 svView 上有一个具有大按钮框架大小的 UIView(例如,buttonView)。之后,您可以在 buttonView(UIview)上添加两个按钮。您必须避免


0
投票

为什么removeButton必须是svObjectButton的子视图?

我认为问题在于 UIButton 是 UIButton 的子视图。尝试将removeButton 添加到svView 中。

© www.soinside.com 2019 - 2024. All rights reserved.