我有一个 NSDictionary,它保存将在数组中使用的对象集,以根据需要创建多个对象。我的图像右上角有一个删除按钮,但由于某种原因,我无法单击它。我会写出来的...
-(void)addItemsToSomething:(NSMutableArray*)array
{
for (NSDictionary *item in array) {
UIImageView *container....
UIImageView *boxInContainer....
UIButton *delete = [UIButton new];
delete.frame = CGRectMake(70, -4, 24, 26);
delete.userInteractionEnabled = YES;
[delete setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[delete addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[boxInContainer addSubview:delete];
some math....
}
more math
}
-(void)delete:(id)sender
{
NSLog(@"Do I work");
}
NSLog 永远不会显示在日志中,按钮阴影也不会显示它已被触摸。我什至将 userInteractionEnabled 设置为 YES 只是为了尝试覆盖另一个基地,但按钮仍然盯着我的脸并且不会单击。谢谢您的帮助。
这也全部放在 ScrollView 上,忘记了那部分。
最佳答案
问题是你把它放在UIImageView
上。 UIImageView
的 userInteractionEnabled
默认设置为 NO。只需更改 boxInContainer.userInteractionEnabled = YES;
按钮就应该可以工作!
哦,如果 boxInContainer
是 container
的 subview ,那么您还必须设置 container.userInteractionEnabled = YES;
关于ios - UIButton不可触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24497796/