【问题标题】:Custom UIButton not capturing touches after adding subview添加子视图后自定义 UIButton 未捕获触摸
【发布时间】:2013-04-01 16:59:35
【问题描述】:

我在界面生成器中声明了一个 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;

【问题讨论】:

  • 您写_gradientButtonView.userInteractionEnabled = YES; 有什么特别的原因吗?据我所知,这会阻止视图向响应者链发送触摸事件。
  • @daltonclaybrook 就是这样。你修好了!随意转发这个作为答案,我会标记它。

标签: objective-c uibutton sstoolkit


【解决方案1】:

上面的cmets已经回答了这个问题:

你写信有什么特别的原因吗 _gradientButtonView.userInteractionEnabled = YES;?据我所知,这会阻止视图向响应者发送触摸事件 链

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    相关资源
    最近更新 更多