I have no idea about the following situation:
I had exported a NSObject from PaintCode and made a .swift file (someObject.swift).
public class PlanATrip: NSObject {
class func drawRectangle1(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 200, height:100), resizing: ResizingBehavior = .aspectFit) {
....
}
I also overrode the draw() function in a UIView (someObjectView.swift).
So how can add a gesture recognizer to a bezierPath (for example, a rectangle1 = UIBezierPath(...) ) which is in the someObject.swift ?
I tried to add some functions like:
let tapGestureA:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(touchAction))
However, the scope confused me; like if I put the touchAction function out of the drawRectangle1 function, I will not be able to access rectangle1.
How can I modify to make such a gesture recognizer work?
You are trying to manipulate
UIBezierPathobjects generated by PaintCode directly, which isn't PaintCode's purpose.What you are trying to achieve is possible, but not without some hacking.
For example: How to access a layer inside UIView custom class generate with Paintcode?
In my opinion, you are "misusing" PaintCode.
Instead, you would be much better adding the tapping logic inside your custom
UIView. The thing you calledsomeObjectView.swift.For example: https://github.com/backslash-f/paint-code-ui-button
In case you really need to check if gestures occur inside the boundaries of a
UIBezierPaththen you need to create a public reference to it (e.g.: avarthat points to it outside of thedrawRectangle1function) and finally use the code proposed by @Sparky.The main problem with this approach is that your changes will be overwritten every time you use PaintCode's export feature. I wouldn't recommend it.