How can I define the custom UIGestureRecognizer in Swift?

落花浮王杯 提交于 2020-01-14 09:54:10

问题


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.

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

How can I import UIGestureRecognizerSubclass and define the custom UIGestureRecognizer?


Edit:

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

#import <UIKit/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?


回答1:


You need to add the import:

import UIKit.UIGestureRecognizerSubclass

as in:

import UIKit
import UIKit.UIGestureRecognizerSubclass


来源:https://stackoverflow.com/questions/24138825/how-can-i-define-the-custom-uigesturerecognizer-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!