gpt4 book ai didi

ios - UISwipeGestureRecognizer 没有可见的接口(interface)声明选择器 'touchesMoved:withEvent:'

转载 作者:行者123 更新时间:2023-11-29 04:24:19 25 4
gpt4 key购买 nike

我收到一个错误。 “UISwipeGestureRecognizer 没有可见的界面声明选择器 'touchesMoved:withEvent:'”

我查看了文档并在 UIGestureRecognizer 类中找到了touchesMoved:withEvent。如何解决这个错误?

@interface MySwipeRecognizer : UISwipeGestureRecognizer

@implementation MySwipeRecognizer

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
@end

最佳答案

除非我误解了这个问题,否则 UISwipeGestureRecognizer 会为您完成所有触摸处理。您的代码将如下所示:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipe:)];

// set a direction for the swipe
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];

// self is a view to add the recognizer to:
[self addGestureRecognizer:swipe];

.
.
.

- (void) onSwipe:(id)sender
{
// a swipe has been recognized!
}

UIGestureRecognizer 是一个抽象类,因此像 UISwipeGestureRecognizer 这样的具体实现会为您完成所有触摸事件处理。如果您尝试创建自己的自定义手势识别器,则需要继承 UIGestureRecognizer。

关于ios - UISwipeGestureRecognizer 没有可见的接口(interface)声明选择器 'touchesMoved:withEvent:',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12570821/

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