我正在使用swift编写一个框架,该框架应该为所有视图添加手势识别器。
所以在我的sample.framework中,我做了类似的事情 -
import UIKit
public class SampleSDK: UIView, UIGestureRecognizerDelegate {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInitialization()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInitialization()
}
func sharedInitialization() {
self.userInteractionEnabled = true
let gesture = UITapGestureRecognizer(target: self, action: #selector(SampleSDK.tapGesture(_:)))
gesture.delegate = self
self.addGestureRecognizer(gesture)
}
func tapGesture(sender: UITapGestureRecognizer){
print("tap working")
}
}
现在我想将此框架添加到现有应用程序中,并希望该应用程序的所有视图都响应tap。
当我添加到任何UIViewController
时self.view = SampleSDK()
这有效,但我不想在每个视图中添加它。这需要是可插拔的。