自定义UIView中的UIButtons没有响应(再次)

时间:2013-03-05 09:35:26

标签: iphone ios uiview uibutton

我有一个自定义UIView,其中一些按钮作为子视图。我读了很多关于我的问题的帖子,但是发布的解决方案对我没有用。

如果我将其中一个按钮的框架设置为我的UIView之外的某些坐标,则该按钮可以正常工作。当我将其中一个按钮的框架设置为自定义UIView和按钮重叠的某些坐标时,该按钮仅响应它们不重叠的区域。

这是我的代码:

我在viewDidLoad方法中初始化自定义UIView:

[super viewDidLoad];

DDButtonBar *ddButtonBar =  _ddButtonBar;

[ddButtonBar showButton1:TRUE];
[ddButtonBar showButton2:TRUE];
[ddButtonBar showButton3:TRUE];
[ddButtonBar showButton4:TRUE];
[ddButtonBar showBackButton:TRUE];
[ddButtonBar showSettingsButton:TRUE];

[ddButtonBar setButtonTitle1:@"1"];
[ddButtonBar setButtonTitle2:@"2"];
[ddButtonBar setButtonTitle3:@"3"];
[ddButtonBar setButtonTitle4:@"4"];

这是我对UIView的初始化方法:

 - (id)initWithFrame:(CGRect)frame

self = [super initWithFrame:frame];
if (self) {

    // Standardinitialisierung
    _drawButton1 = TRUE;
    _drawButton2 = TRUE;
    _drawButton3 = TRUE;
    _drawButton4 = TRUE;
    _drawBackButton = TRUE;
    _drawSettingsButton = TRUE;

    _buttonTitle1 = @"1";
    _buttonTitle2 = @"2";
    _buttonTitle3 = @"3";
    _buttonTitle4 = @"4";

    [self layoutSubviews];


}
return self;

}

我正在按我的按钮

 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self
            action:@selector(aMethod:)
  forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:_buttonTitle1 forState:UIControlStateNormal];

button1.frame = CGRectMake(rechtsverschiebung, height, buttonWidth, height);

[button1 setBackgroundImage:_buttonBackground forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor colorWithRed:255.0 green:255.0 blue:255 alpha:1.0] forState: UIControlStateNormal];
[button1 setTitleColor:[UIColor colorWithRed:247.0 green:165.0 blue:32 alpha:1.0] forState: UIControlStateHighlighted];

[self addSubview:button1];

1 个答案:

答案 0 :(得分:0)

检查下一个按钮的y位置。在代码中,为所有按钮设置相同的y位置。