gpt4 book ai didi

ios - 即使未实现,uilongpressgesturerecognizer 也会崩溃

转载 作者:可可西里 更新时间:2023-11-01 05:01:33 26 4
gpt4 key购买 nike

我尝试了所有可能的搜索,但在一个星期内没有找到任何类似的东西。我正在制作一个显示表格 View 的应用程序。可以使用 Cell 类中的 UIPanGestureRecognizer 拖动单元格(由自定义类和 Interface Builder 制作)。一切正常,除了当我将手指按住单元格时,应用程序因错误而崩溃:

-[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(在单元格类中,在 TableView 的类中,在分配每个单元格之前)但错误仍然相同(我在主题中查看了许多线程并相信我,语法是正确的。

如果您需要任何其他文档,请随时询问(这是我在这里的第一篇文章,我不知道我必须展示什么)。

感谢您宝贵的帮助。

好的,问题仍然存在,抱歉打扰了:(我设法设置了一个断点并打印了堆栈跟踪。这是:

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

应用程序阻塞代码:

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

编辑我通过拦截 UILongPressGestureRecognizer 解决了,这样安全吗?

-(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;}

最佳答案

我通过检查您收到的 gestureRecognizer 的 type 解决了这个问题。

有时我会收到“UILongPressGestureRecognizer”而不是“UIPanGestureRecognizer”。

试试这个:

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

return YES;
}
return NO;
}

更新

swift 2.0版本

override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
guard let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return false }

let translation = panGestureRecognizer.translationInView(self.superview)
}

关于ios - 即使未实现,uilongpressgesturerecognizer 也会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16239143/

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