ios - 将长按手势添加到 Scrollview 中的 UIImageView

标签 ios uiscrollview uiimageview uigesturerecognizer

我已经为此研究了几个小时,但似乎没有任何效果。我有一个 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];

最佳答案

imageView.userInteractionEnabled = YES; 不需要,它总是工作正常。将委托(delegate)设置为 gestureRecognizer 也是可选的。首先尝试将 imageView 添加到 self.scroll subview 而不是 bgImageView。之后检查您的 scrollView 内容大小,如果您的图像超出 dat 大小,它可以可见但不可用。尝试用 uibutton 替换 imageview 并检查它的 uitouchupinside 事件。

关于ios - 将长按手势添加到 Scrollview 中的 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25716821/

相关文章:

ios - Apple Mach-O错误Xcode-真的很困惑

iphone - UIScrollView如何自动包裹内容?

ios - UIScrollView 从中心到左右分页

ios - 在 subview 中应用任何 "transform"后缩放 UIScrollView

iphone - UIImageView 在 iPhone 4 上缩小

swift - 当 contentmode 为 Scale to fill 时,UIImageView 会更改其大小

ios - 在没有 CoreText 的情况下将 UITextView 中的文本环绕在 UIImage 周围

objective-c - "Game Center account services are currently unavailable"在模拟器上

ios - 检测图像的模糊部分

iOS 13 强制应用显示蓝牙权限提示