【问题标题】:UIButton not receiving clicksUIButton 没有收到点击
【发布时间】:2011-04-17 20:51:10
【问题描述】:

所以这是我的代码:

    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


    【解决方案1】:

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

                [svObjectButton addSubview:removeButton];
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-08-08
        • 2021-12-07
        • 1970-01-01
        • 1970-01-01
        • 2019-02-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多