UIButton在自定义CALayer分配后未检测到触摸

时间:2012-10-13 15:55:00

标签: objective-c ios uibutton calayer

我的UIButton的目标操作不会被调用,除非下面的委托分配被注释掉,但是我丢失了我的自定义绘图。我错过了什么?

- (void)createLayerForPaletteAtIndex:(int)paletteIndex onButton:(UIButton *)button
{
    self.colorPaletteLayer            = button.layer;
    self.colorPaletteLayer.delegate   = self; // Must implement drawLayer:inContext
    NSString *stringForIndex          = [NSString stringWithFormat:@"%d",paletteIndex];
    self.colorPaletteLayer.name       = stringForIndex;
    button.clearsContextBeforeDrawing = YES;
    button.layer.opaque               = YES;
    [self.colorPaletteLayer setNeedsDisplay]; // Calls drawLayer:inContext
}

1 个答案:

答案 0 :(得分:1)

你正在劫持按钮的图层。你不应该这样做。 UIKit不希望你这样做。您应该创建一个子图层并将其添加到按钮的图层。