如何在Swift中定义自定义UIGestureRecognizer? [英] How can I define the custom UIGestureRecognizer in Swift?

查看:107
本文介绍了如何在Swift中定义自定义UIGestureRecognizer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Swift中定义自定义UIGestureRecognizer,但我无法导入UIGestureRecognizerSubclass,也无法覆盖touchesBegan,touchesMoved等方法。

I want to define the custom UIGestureRecognizer in Swift, but I cannot import UIGestureRecognizerSubclass and cannot override the methods of "touchesBegan", "touchesMoved", and so on.

UIGit模块中有UIGestureRecognizerSubclass.h,但是只能在Swift中导入模块,并且无法导入头文件。

"UIGestureRecognizerSubclass.h" is in the UIKit module, but only modules can likely be imported in Swift and header files cannot be imported.

如何导入UIGestureRecognizerSubclass并定义自定义UIGestureRecognizer?

How can I import UIGestureRecognizerSubclass and define the custom UIGestureRecognizer?

编辑:

我添加了在Bridging-Header.h中的代码下方,我成功编译了我的自定义手势识别器。

I added the below code in Bridging-Header.h and I successfully compiled my custom gesture recognizer.

#import <UIKit/UIGestureRecognizerSubclass.h>

但是这段代码可能会为我项目中的每个swift文件导入UIGestureRecognizerSubclass.h,所以我是认为这不是最好的方式。

But this code may import "UIGestureRecognizerSubclass.h" for every swift files in my project, so I am thinking it is not the best way.

这是正确的方法吗?
还有其他合适的解决方案吗?

Is it right way? Is there another proper solution?

推荐答案

您需要添加导入:

import UIKit.UIGestureRecognizerSubclass

as in:

import UIKit
import UIKit.UIGestureRecognizerSubclass

这篇关于如何在Swift中定义自定义UIGestureRecognizer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆