0

如果我将它更改为 timerView 的子视图,它可以正常工作,但没有其他工作。

timerView = [[UIView alloc] initWithFrame:CGRectMake(0, 278, 105, 33)];
[self.view addSubview:timerView];

UIImageView *changerBackground = [[UIImageView alloc] init];
[changerBackground setImage:[UIImage imageNamed:@"speedbackground.png"]];
changerBackground.frame = CGRectMake(-12 , -16, 105, 33);
[timerView addSubview:changerBackground];

UIButton *normal = [UIButton buttonWithType:UIButtonTypeCustom];
normal.frame = CGRectMake(40, 8, 22, 22);
[normal setBackgroundImage:[UIImage imageNamed:@"normalwhite.png"] forState:UIControlStateNormal];
[normal setBackgroundImage:[UIImage imageNamed:@"normalred.png"] forState:UIControlStateHighlighted];
[normal addTarget:self action:@selector(quickTest:) forControlEvents:UIControlEventTouchUpInside];
[changerBackground addSubview:normal];
4

1 回答 1

1
[changerBackground setUserInteractionEnabled:YES];

将解决您的问题。由于 UIImageView 默认禁用用户交互。

于 2012-11-27T01:17:16.047 回答