Ios 在Scrollview中向UIImageView添加长按手势

Ios 在Scrollview中向UIImageView添加长按手势,ios,uiscrollview,uiimageview,uigesturerecognizer,Ios,Uiscrollview,Uiimageview,Uigesturerecognizer,我已经研究了几个小时了,但似乎什么都不管用。我有一个UIScrollView作为IBOutlet,并通过代码添加了两个UIImageView。一个是背景图像,第二个是照片。这里一切都很好。我正试图在第二张照片上加上一个长长的按下手势,但似乎不起作用。这是我的密码。我希望有人能看到我的问题 // loop thru images array UIImage *bgFrame = [UIImage imageNamed:@"photo-frame.png"]; UIImag

我已经研究了几个小时了,但似乎什么都不管用。我有一个UIScrollView作为IBOutlet,并通过代码添加了两个UIImageView。一个是背景图像,第二个是照片。这里一切都很好。我正试图在第二张照片上加上一个长长的按下手势,但似乎不起作用。这是我的密码。我希望有人能看到我的问题

    // loop thru images array

    UIImage *bgFrame = [UIImage imageNamed:@"photo-frame.png"];
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgFrame];
    bgImageView.frame = CGRectMake(posX, posY, 100, 100);
    [self.scroll addSubview:bgImageView];

    NSString *photoName = [self.photoArray objectAtIndex:i];
    UIImage *photo = [self.utils getClientPhoto:photoName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:photo];
    imageView.userInteractionEnabled = YES;
    imageView.frame = CGRectMake(6, 9, 89, 71);
    imageView.tag = i;
    [bgImageView addSubview:imageView];

    // add long press for deletion
    UILongPressGestureRecognizer *lPressed = [[UILongPressGestureRecognizer alloc]
                                              initWithTarget:self action:@selector(imageLPressed:)];
    lPressed.delegate = self;
    lPressed.minimumPressDuration = 0.4;
    [imageView addGestureRecognizer:lPressed];

bImageView
imageView
上启用
UserInteraction
imageView.userInteractionEnabled=YES不需要,它总是工作正常。将委托设置为手势识别器也是可选的。首先,尝试将imageView添加到self。滚动子视图,而不是bImageView。之后,检查您的scrollView内容大小,如果您的图像超出dat大小,它可以是可见的,但不可用。尝试将imageview替换为uibutton,并检查其uitouchupinside事件