简体   繁体   English

IOS:UILongPressGestureRecognizer EXC_BAD_ACCESS

[英]IOS: UILongPressGestureRecognizer EXC_BAD_ACCESS

I have this code in viewDidLoad: 我在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; 当我调用这个代码的类时,第一次它都没问题,但第二次崩溃是因为EXC_BAD_ACCESS; it don't happens if instead of an imageView I use a scrollView, why??? 它不会发生如果不是一个imageView我使用scrollView,为什么???

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. 不知道这是否真的可以解决您的问题,在您发布的内容中看不到任何其他错误。

Maybe try this: UIButtonLongTab . 也许试试这个: UIButtonLongTab Use the Background-Image for your Images. 使用背景图像为您的图像。 I use this in an App within a ScrollView and it works without problem. 我在ScrollView中的应用程序中使用它,它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM