这是一个可能令人尴尬的问题,所以如果我遗漏了一些显而易见的事情,那就轻松一下吧。
我有以下设置:3个UIViews声明为属性,并排放在scrollview(也是属性)中。在所有这些我放置一个容器(self.view的孩子),没有定义为属性。在这个容器中,我有三个按钮,未定义为属性。问题是按钮只会在设置为子项时触发,如下所示:
self.view> buttons =>作品
self.view>容器(不是属性)=>不起作用
self.view>容器(属性)=>不起作用
我无法想象当放入包含UIView时按钮不会触发的原因。代码如下所示:
//now draw the left panel:
panel1 = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.screenWidth,self.screenHeight)];
panel1.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:totalTransparent];
[self.scrollView addSubview:panel1];
//now draw the middle panel:
panel2 = [[UIView alloc] initWithFrame:CGRectMake(self.screenWidth,0,self.screenWidth,self.screenHeight)];
panel2.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:panel2];
//now draw the right panel:
panel3 = [[UIView alloc] initWithFrame:CGRectMake(self.screenWidth*2,0,self.screenWidth,self.screenHeight)];
panel3.backgroundColor = [BGColor colorWithAlphaComponent:bgAlpha2];
[self.scrollView addSubview:panel3];
//bottom three buts
UIView *bottomButs = [[UIImageView alloc]initWithFrame:CGRectMake(1, self.screenHeight - 1 - blockHeight, self.screenWidth - 2, blockHeight)];
bottomButs.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:blackTransparent];
[self.view addSubview:bottomButs];
UIButton *botButMusic = [UIButton buttonWithType:UIButtonTypeCustom];
[botButMusic addTarget:self action:@selector(goToPanel1) forControlEvents:UIControlEventTouchUpInside];
[self activateButton:botButMusic];
botButMusic.frame = CGRectMake(1, 1, 104, buttonHeight);
botButMusic.backgroundColor = [buttonBGColor colorWithAlphaComponent:whiteTransparent];
[botButMusic setBackgroundImage:[UIImage imageNamed:@"3butMusic.png"] forState:UIControlStateNormal];
[bottomButs addSubview:botButMusic];
UIButton *botButCamera = [UIButton buttonWithType:UIButtonTypeCustom];
[botButCamera addTarget:self action:@selector(goToPanel2) forControlEvents:UIControlEventTouchUpInside];
[self activateButton:botButCamera];
botButCamera.frame = CGRectMake(106, 1, 105, buttonHeight);
botButCamera.backgroundColor = [buttonBGColor colorWithAlphaComponent:whiteTransparent];
[botButCamera setBackgroundImage:[UIImage imageNamed:@"3butCamera.png"] forState:UIControlStateNormal];
[bottomButs addSubview:botButCamera];
UIButton *botButWatch = [UIButton buttonWithType:UIButtonTypeCustom];
[botButWatch addTarget:self action:@selector(goToPanel3) forControlEvents:UIControlEventTouchUpInside];
[self activateButton:botButWatch];
botButWatch.frame = CGRectMake(212, 1, 105, buttonHeight);
botButWatch.backgroundColor = [buttonBGColor colorWithAlphaComponent:whiteTransparent];
[botButWatch setBackgroundImage:[UIImage imageNamed:@"3butWatch.png"] forState:UIControlStateNormal];
[bottomButs addSubview:botButWatch];
我错过了什么?
答案 0 :(得分:0)
所有超级视图的userInteractionEnabled = true吗?