gpt4 book ai didi

ios - UICollectionView Objective-c的长按轻击手势识别器

转载 作者:行者123 更新时间:2023-12-01 20:08:14 24 4
gpt4 key购买 nike

我在ViewController中使用UICollectionView来显示图像,我希望该用户在长按时应该能够删除照片,但是我无法检测到长按手势。我已经阅读了之前的所有讨论,并尝试在我的项目中实施它们,但是没有一个对我有用。

最佳答案

通过下面的行为您的imageview启用用户交互

imgview.userInteractionEnabled =YES;

//这里是示例代码
UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[gestureRecognizer addTarget:self action:@selector(imgLongPressed:)];
gestureRecognizer.delegate = self;
imgview.userInteractionEnabled =YES;
[imgview addGestureRecognizer: gestureRecognizer];

- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
UIImageView *view_ =(UIImageView*) sender.view;
CGPoint point = [sender locationInView:view_.superview];

if (sender.state == UIGestureRecognizerStateBegan)
{

}
else if (sender.state == UIGestureRecognizerStateChanged)
{

}
else if (sender.state == UIGestureRecognizerStateEnded)
{

}

}

关于ios - UICollectionView Objective-c的长按轻击手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38242680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com