UIPangestureRecognizer

UIPangestureRecognizer

本文介绍了即使没有实施,uilongpressgesturerecognizer也会崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了每次搜索,但在一周内没有发现任何相似之处。
我正在制作一个显示表格视图的应用程序。单元格(由自定义类和Interface Builder制作)可以使用属于Cell类的UIPanGestureRecognizer进行拖动。
一切正常,但是当我将手指按在一个单元格上时,应用程序会因错误而崩溃:

I tried every search possible but I didn't find anything similar in one week.I am making an application that displays a table view. Cells (made by a custom class and with Interface Builder) can be dragged with a UIPanGestureRecognizer that is pu in the Cell's class.Everything works fine except that when I keep the finger pressed on a cell the app crashes with the errors:

-[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x94670a0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x94670a0'

我知道它的含义(通常是发送给实例的错误参数),但我真的不知道如何这是可能的,因为我的代码中没有UILongPressGestureRecognizer的痕迹。
我试图拦截LongPressGestureREcognizer EVEWHERE(在单元格类中,在tableview的类中,在分配每个单元格之前)但是错误仍然是相同的(我在这里查看了许多线程,相信我,语法是对的。

I know what it does mean (usually a wrong parameter sent to an instance), but I really don't know how is this possible, since there's no trace of a UILongPressGestureRecognizer in my code.I tried to intercept the LongPressGestureREcognizer EVERYWHERE (in the cell class, in the tableview's class, before the allocation of every cell) but the error is still the same (i looked at many threads here in the subject and trust me, syntax was right.

如果你想让任何其他文件随意问(这是我在这里的第一篇文章,我不知道我要展示的内容)。

If you want any other documentation feel free to ask (it's my first post here I don't know exactly what I have to show).

谢谢你的宝贵帮助。

好的问题仍然是抱歉打扰:(我不知何故设法设置断点并打印堆栈跟踪。这是:

Ok the problem is still there sorry for bothering :( I somehow managed to set a breakpoint and print the stack trace. Here it is:

0   uBellow                             0x0000ac57 -[OpinionCell gestureRecognizerShouldBegin:] + 71
1   UIKit                               0x00914939 -[UIGestureRecognizer _shouldBegin] + 1334
2   UIKit                               0x0091181a -[UIGestureRecognizer setState:] + 152
3   UIKit                               0x00921cea -[UILongPressGestureRecognizer enoughTimeElapsed:] + 127
4   libobjc.A.dylib                     0x017186b0 -[NSObject performSelector:withObject:] + 70
5   UIKit                               0x00787954 -[UIDelayedAction timerFired:] + 83
6   Foundation                          0x0114d2c0 __NSFireTimer + 97
7   CoreFoundation                      0x01bce376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
8   CoreFoundation                      0x01bcde06 __CFRunLoopDoTimer + 534
9   CoreFoundation                      0x01bb5a82 __CFRunLoopRun + 1810
10  CoreFoundation                      0x01bb4f44 CFRunLoopRunSpecific + 276
11  CoreFoundation                      0x01bb4e1b CFRunLoopRunInMode + 123
12  GraphicsServices                    0x022337e3 GSEventRunModal + 88
13  GraphicsServices                    0x02233668 GSEventRun + 104
14  UIKit                               0x00648ffc UIApplicationMain + 1211
15  uBellow                             0x0000287d main + 141
16  uBellow                             0x000027a5 start + 53

代码上的应用程序块:

The app blocks on the code:

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
CGPoint translation = [gestureRecognizer translationInView:[self superview]];

编辑
我通过拦截UILongPressGestureRecognizer解决了,这是一种安全的方法吗?

editI solved by intercepting UILongPressGestureRecognizer, is it a safe way?

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
    return NO;
}else{
CGPoint translation = [gestureRecognizer translationInView:[self superview]];
// Check for horizontal gesture
if (fabsf(translation.x) > fabsf(translation.y)){
    return YES;
}
}
return NO;}


推荐答案

在你的:

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer

尝试更改:

 CGPoint translation = [gestureRecognizer translationInView:[self superview]];

收件人:

 CGPoint translation = [gestureRecognizer locationInView:[self superview]];

希望这会有所帮助。

这篇关于即使没有实施,uilongpressgesturerecognizer也会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:46