我正在向 UIView 添加 3 个 UIButton,通常只有 1 到 2 个会检测到触摸,即使这样,它也只会是检测它们的按钮的上半部分。有谁知道为什么会发生这种情况?
for (int i = 0; i <= 2; i++) {
int randIndex = arc4random() % [images count];
// UIImage *randImage = [images objectAtIndex:randIndex];
NSString *number = [numbers objectAtIndex:randIndex];
[images removeObjectAtIndex:randIndex];
[numbers removeObjectAtIndex:randIndex];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// [button setImage:randImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpOutside];
button.frame = CGRectMake(0, 8, 108, 40);
button.tag = [number integerValue];
for (UIView *sub in [baseone subviews]) {
CGPoint topRight = CGPointMake(sub.frame.origin.x + sub.frame.size.width, sub.frame.origin.y);
button.frame = CGRectMake(topRight.x, 8, 108, 40);
}
[baseone addSubview:button];
}