하위 뷰로 일부 단추가있는 사용자 지정 UIView가 있습니다. 내 문제에 대해 많은 글을 읽었지 만 게시 된 솔루션이 나에게 도움이되지 못했습니다.사용자 지정 UIView의 UIButtons가 응답하지 않습니다 (다시)
단추 중 하나의 프레임을 UIView 외부의 일부 좌표로 설정하면 단추가 작동합니다. 단추 중 하나의 프레임을 사용자 지정 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;
: 이것은 UIView의 내 init 메소드
[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"];
입니다 : 내가있는 viewDidLoad 방법에서 사용자 지정 UIView의 초기화
:
이
내 코드입니다 }나는 당신의 코드는 모든 버튼에 대해 동일한 y 위치를 설정하는
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];
[self.view bringSubviewtofront :]; 이것을 시도하십시오 –
amar
나는 그것을 벌써 시도했다, 내가 정확하게했던 것을 게시 할 것이다. 내 viewDidLoad [self.view bringSubviewToFront : _ddButtonBar]에서 이것을 시도했다; 그리고 내 사용자 정의 UIView [self bringSubviewToFront : button1]; 내 사용자 정의 UIView에서 [self.view ...]을 사용할 수 없습니다. – user2135074
가장 좋은 방법은 모든보기에 다른 색상을 지정하는 것입니다. 어떤보기가 단추 위에 있는지 보거나 단추가 사각형이 추가 된보기의 사각형 외부로 나올 수 있습니다. – amar