【问题标题】:Why User Interaction Enabled is Necessary for the Target too Instead of Just the Button?为什么目标也需要启用用户交互而不仅仅是按钮?
【发布时间】:2012-10-30 07:39:26
【问题描述】:
UIButton * newButton = [UIButton buttonWithType:UIButtonTypeCustom];
newButton.imageObject= someImage;
UIImage * imagePut  = someImage.imageBlob;
imagePut = [imagePut roundedCornerImage:20 borderSize:0];
[newButton setImage:imagePut forState:UIControlStateNormal];

newButton.frame= CGRectMake(column * self.distanceBetweenButton +marginBetweenButtons, row *self.distanceBetweenButton+marginBetweenButtons, self.sizeOfButtons, self.sizeOfButtons);
newButton.backgroundColor = [UIColor clearColor];
PO(@(newButton.userInteractionEnabled));
newButton.userInteractionEnabled=YES;
[newButton addTarget:self action:@selector(someImageGotPressed) forControlEvents:UIControlEventTouchUpInside];
PO(@([newButton allControlEvents]));
PO(newButton.allTargets);
[self.collectionOfButton addObject:newButton];

简单的按钮。问题是 someImageGotPressed 从未被调用过。

newButton 当然默认有 userInteractionEnabled。但是,仍然没有调用 someImageGotPressed。

目标是一个 UITableViewCell。我关闭了该 uiTableViewCell 的 userinteractionenabled,因为我希望人们与按钮进行交互。

我把它重新打开,它可以工作。

但是,有些事情让我感到困惑。 addTarget 中的目标可以是任何正确的。它甚至不必是 UIView 或 UIViewController。那么,为什么目标的 userInteractionEnabled 很重要呢?

这是因为 UITableViewCell 是按钮的超级视图,关闭视图的 userInteractionEnabled 会在它的所有超级视图或类似的东西中关闭它吗?

【问题讨论】:

    标签: objective-c xcode uiview user-interaction


    【解决方案1】:

    当您将超级视图的userInteractionEnabled (UITableViewCell) 设置为 NO 时,也会导致忽略对其子视图的所有触摸事件。

    【讨论】:

    • 这里的答案是正确的,但没有提供解决方案。这是一个可能的解决方案:link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    相关资源
    最近更新 更多