如果我的故事板包含
View
|_my UIIMageView 1
|
|_my UIImageView 2
我可以按照此post
的解决方案来处理触地事件但是,如果我的故事板改为
Scroll View
|_my UIIMageView 1
|
|_my UIImageView 2
现在我无法在其中一个UIImageView上检测到触碰事件...... 请帮我解决这个问题..
答案 0 :(得分:0)
可能不是您正在寻找的答案,但您应该考虑使用UIButtons而不是UIImageViews。
每个UIButton都有一个UIImageView以及它的所有触摸事件。
答案 1 :(得分:0)
我用过:
UITapGestureRecognizer *touch;
UIImageView *anImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
anImageView.image = [UIImage imageNamed:@"iad.png"];
[anImageView setUserInteractionEnabled:TRUE];
anImageView.tag = 1001 ;
touch = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)] autorelease];
touch.numberOfTapsRequired = 1;
[anImageView addGestureRecognizer:touch];
[scrollView addSubview:anImageView];
[anImageView release];
- (void) test:(UIGestureRecognizer *)sender
{
UIImageView *imageView = (UIImageView *)sender.view;
switch (imageView.tag)
{
case 1001:
// your code
break;
case 1002:
// your code
break;
}
}