Gab
Gab

Reputation: 19

Drawing in an NSView and Subclassing

I am rewriting a pretty large drawing program, now that Xcode uses Storyboards for Cocoa apps, and was just confused about a few things regarding optimization.

Let's say I have a drawing program where the user can draw different shapes (rectangles, triangles, circles, stars; etc) onto the NSView (Subclass: MyDrawing). Cleary these shapes' points will have to be saved in an array for drawRect to recall for later so that they don't get cleared, However I noticed that the more shapes there were DrawRect/Core Graphics really bogged down and when resizing shapes, it was very laggy.

What would the best practice in this sort of thing be? Should I create a separate class for each shape? Should I create a new NSView for each shape? (Although the second one doesn't make much sense to me)

All I did before was invoke the drawinRect method to update certain parts of the NSView, but found that it was still a little slow.

What is the best most optimal way be to go about drawing multiple shapes (while letting the user edit them later on) ?

Upvotes: 0

Views: 161

Answers (1)

Sheen Vempeny
Sheen Vempeny

Reputation: 826

I suggest CALayer's inside NSView.

Upvotes: 0

Related Questions