Background: Assume you are in the "override func drawRect(rect: CGRect)" method of a custom UIView class (call it View 1), then
Question: What would be the code to, all within this drawRect method from view 1 (i.e. in the same method in the same file, so without creating another class), to create a subview (call it View 2) and draw into this. So let's say to programmatically:
- Create a Subview (View 2)
- Draw into this Subview (say a UIBezierPath)
- Add methods for this subview, e.g. for touch (e.g. touchesMoved:withEvent:)
- Add this subview (View 2) into View 1
Is this possible? Or does such drawing in IOS/Swift really require you to create a new class (e.g. custom sub-class of UIView) for this?
EDIT/MORE BACKGROUND: I've come across from CoronaSDK and trying to understand the IOS/Swift approach. In corona for example you could, within the same method, do something like: - draw a face as a circle - insert eyes as separate images - insert a nose as say a line path - for each of these add listeners with specific methods (e.g. if touch left eye then do X, etc)
So all of this within one file (same method even). So I'm now trying to wrap my head around IOS and it seems in this case you would have to have separate files defining custom UIView classes for each of these. It seems they have to be UIViews (as layers don't accept touch), and also to set their own callbacks for touch events(?)
drawRect
method would result in multiple subviews being added unless you add some workaround. What are your requirements? Why would you think of doing it that way? – Adam