添加子视图后,自定义UIButton不捕获触摸

时间:2013-04-01 16:59:36

标签: objective-c uibutton sstoolkit

我在界面构建器中声明了一个UIButton,其插座设置如下:

@property (weak, nonatomic) IBOutlet UIButton *loginButton;

在我插入子视图之前一切正常。然后它停止响应。这是违规行:

[self.loginButton insertSubview:_gradientButtonView atIndex:0];

注释掉该按钮会使按钮再次工作。这是所有涉及的代码(使用真棒SSToolkit和UIColor上的自定义类别):

SSGradientView *_gradientButtonView = [[SSGradientView alloc] initWithFrame:self.loginButton.layer.bounds];
_gradientButtonView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_gradientButtonView.topBorderColor = [UIColor colorWithRed:0.558f green:0.599f blue:0.643f alpha:1.0f];
_gradientButtonView.topInsetColor = [UIColor colorWithWhite:1.0f alpha:0.3f];
_gradientButtonView.colors = [NSArray arrayWithObjects:[UIColor from_hex:@"E6E7E8"], [UIColor from_hex:@"A7A9AC"], nil];
_gradientButtonView.layer.cornerRadius = 5;
self.loginButton.layer.cornerRadius = 5;
self.loginButton.titleLabel.shadowOffset = CGSizeMake(0, 1);
[self.loginButton setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.loginButton.layer.masksToBounds = YES;
_gradientView.bottomBorderColor = [UIColor colorWithRed:0.428f green:0.479f blue:0.520f alpha:1.0f];
_gradientButtonView.clipsToBounds = YES;
_gradientButtonView.userInteractionEnabled = YES;
[self.loginButton insertSubview:_gradientButtonView atIndex:0];
self.loginButton.userInteractionEnabled = YES;

1 个答案:

答案 0 :(得分:0)

以上评论回答:

  

你有没有特别的理由写作   _gradientButtonView.userInteractionEnabled = YES;?据我所知,这可以防止视图向响应者发送触摸事件   链

相关问题