iOS:UILongPressGestureRecognizer EXC_BAD_ACCESS

发布于 2024-12-18 07:29:35 字数 507 浏览 2 评论 0原文

我在 viewDidLoad 中有这段代码:

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
    [imageView addGestureRecognizer:change];
    for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
    {
        [gestureRecognizer requireGestureRecognizerToFail:change];
    }

当我调用这个代码在哪里的类时,第一次一切正常,但第二次它崩溃,因为 EXC_BAD_ACCESS;如果我使用scrollView而不是imageView,就不会发生这种情况,为什么???

I have this code in viewDidLoad:

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
    [imageView addGestureRecognizer:change];
    for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
    {
        [gestureRecognizer requireGestureRecognizerToFail:change];
    }

when I call the class where is this code, the first time it's all ok , but the second time it crash because EXC_BAD_ACCESS; it don't happens if instead of an imageView I use a scrollView, why???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心 2024-12-25 07:29:35

使用此代码,您需要所有识别器(包括更改)失败才能更改成功,这不太好,

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
[imageView addGestureRecognizer:change];
for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
{
    [gestureRecognizer requireGestureRecognizerToFail:change];
}

您应该将其更改为此

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
{
    [gestureRecognizer requireGestureRecognizerToFail:change];
}
[imageView addGestureRecognizer:change];

并且您应该在此处发布更改。不知道这是否能真正解决您的问题,在您发布的内容中看不到任何其他错误。

With this code, you are requiring all recognizers (including change) to fail for change to succeed, which cannot be good

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
[imageView addGestureRecognizer:change];
for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
{
    [gestureRecognizer requireGestureRecognizerToFail:change];
}

you should change it to this

UILongPressGestureRecognizer *change = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(dragGestureChange:)];
for (UILongPressGestureRecognizer *gestureRecognizer in imageView.gestureRecognizers)
{
    [gestureRecognizer requireGestureRecognizerToFail:change];
}
[imageView addGestureRecognizer:change];

And you should release change here. Don't know if that will actually solve your problem, can't see anything else wrong in what you posted.

紫罗兰の梦幻 2024-12-25 07:29:35

也许可以尝试这个:UIButtonLongTab。使用背景图像作为您的图像。我在 ScrollView 内的应用程序中使用它,它工作没有问题。

Maybe try this: UIButtonLongTab. Use the Background-Image for your Images. I use this in an App within a ScrollView and it works without problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文