我有一个UIButton
.它有两个子视图.然后我打电话给:
[createButton addTarget:self action:@selector(openComposer) forControlEvents:UIControlEventTouchUpInside];
如果我点击UIButton
那些未被覆盖的部分,但是它的一个子视图,它可以正常工作.但是,如果我点击其中一个子视图,则不会触发该操作.
在两个子视图中,我已经.userInteractionEnabled
设置为YES
.
这两个子视图都是UIViews
带有frame
和的backgroundColor
.
如何让水龙头"通过" UIView
并进入UIButton
?
谢谢
编辑:我需要使用UIControlEvents因为我需要UIControlEventTouchDown.
编辑2:
这是按钮的代码.
@interface CreateButton () @property (nonatomic) Theme *theme; @property (nonatomic) UIView *verticle; @property (nonatomic) UIView *horizontal; @property (nonatomic) BOOL mini; @end @implementation CreateButton #pragma mark - Accessors - (UIView *)verticle { if (! _verticle) { _verticle = [[UIView alloc] init]; _verticle.backgroundColor = [self.theme colorForKey:@"createButtonPlusBackgroundColor"]; _verticle.userInteractionEnabled = NO; } return _verticle; } - (UIView *)horizontal { if (! _horizontal) { _horizontal = [[UIView alloc] init]; _horizontal.backgroundColor = [self.theme colorForKey:@"createButtonPlusBackgroundColor"]; _verticle.userInteractionEnabled = NO; } return _horizontal; } #pragma mark - Init - (instancetype)initWithTheme:(Theme *)theme frame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _theme = theme; self.layer.cornerRadius = roundf(frame.size.width / 2); self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOpacity = .1f; self.layer.shadowOffset = CGSizeZero; self.layer.shadowRadius = 15.f; self.backgroundColor = [self.theme colorForKey:@"createButtonBackgroundColor"]; [self addSubview:self.verticle]; [self addSubview:self.horizontal]; [self addTarget:self action:@selector(animate) forControlEvents:UIControlEventTouchDown]; [self addTarget:self action:@selector(animate) forControlEvents:UIControlEventTouchUpInside]; [self addTarget:self action:@selector(animate) forControlEvents:UIControlEventTouchUpOutside]; } return self; } #pragma mark - Actions - (void)animate { [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:8 options:kNilOptions animations:^{ if (self.mini) { self.transform = CGAffineTransformMakeScale(1.0, 1.0); self.mini = NO; } else { self.transform = CGAffineTransformMakeScale(0.90, 0.90); self.mini = YES; } } completion:nil]; } #pragma mark - UIView - (void)layoutSubviews { CGSize size = self.bounds.size; NSInteger width = 3; NSInteger verticleInset = 12; self.verticle.frame = CGRectMake((size.width - width) / 2, verticleInset, width, size.height - (verticleInset * 2)); self.horizontal.frame = CGRectMake(verticleInset, (size.height - width) / 2, size.width - (verticleInset * 2), width); } @end
TylerTheComp.. 31
设置userInteractionEnabled
到NO
你的子视图,让触摸通过他们到您的按钮.
还要确保_verticle.userInteractionEnabled = NO;
为您的horizontal
房产改变您的懒人装载机,_horizontal.userInteractionEnabled = NO;
因为我认为这是一个错字.