This was a really nice tutorial, and it reminds me I’m still interested in this one part:
you had to do complex things like convert your strokes to spline curves to make drawings look decent
I’d really like to know how to do that, especially to make a blek style line, or one that let’s say thickens and burns as the swipe happens, and thins out towards its constantly moving tail…
even though the coalescing touches added a bit of resolution, i could still see those straight lines between points that I’d prefer to be curved.
luckily i know about bezier paths and control points… i just need to understand the syntax of handling the array of touches that is built and used to draw the chunks of line…
I guess I’ll play with that tutorial and see if swiftify.co is helpful
I didn’t know about swiftify.co. What a great idea! Having said that, in my opinion, it’s a good idea to muddle through Objective C sites because there are a lot of valuable Objective C tutorials and projects out there. And in most cases, it’s a simple translation.
that’s a good point… I’m trying not to fill my head with too much C but perhaps a little wouldn’t be horrid. I’m still interested in finding out how to make a blek (app) style line, taking advantage of all the coalescing touches and so forth.
also interesting to me is the audio synth abilities of iOS, especially by making the sounds blek does when drawing…
I'd like the drawn image to stay the same size in both portrait and landscape.
The code works great for when the ContentMode is set to .ScaleToFill.
But if I set the ContentMode to a non-scaled mode like .TopRight and rotate the screen, the image proportions change when touchesMoved is fired. I think it has to do with placing the drawingImage into the context using a bounds that was different from the previous rotation, but I can’t figure out how get it to draw with the correct proportions.
I’ve tried storing and using a previous bounds (before rotation), setting the ContentMode before and after adding the drawingImage to the context, and even looking at manipulating cg/ci Image data using extent, etc…
That’s where the painted view does not rotate, but any other views do. If you just want to turn off rotation for the whole app, you can do it in the Project Target settings as the Scribble starter project does.
I’ve taken a combination of this:
and this:
I couldn’t get the Apple suggestion to do what I wanted it to do, but removing auto layout from the canvasView and putting it into a xib allowed me to rotate it as per the stackOverflow link.
The attached zip is my suggestion. (I changed eraser color to green for testing on the simulator.)
Thank you. I didn’t think of using CGAffineTransform!
I did remove auto layout for the canvas view and set the contentMode to topRight (and extended the view so that it covers both landscape and portrait). But was hoping that there was some trick with drawing into the context.
I was wondering how can we save and edit previous drawing.
I used this to save the drawing:
let data = UIImagePNGRepresentation(canvasView.image!)
let userDefaults = UserDefaults.standard
userDefaults.set(data, forKey: “test1”)
userDefaults.synchronize()
And used this to retrieve the files:
if let data = UserDefaults.standard.data(forKey: “test123”),let image = UIImage(data: data,scale:1.0){
canvasView.image = image
}
But when i started to edit retrieve files all drawing has been deleted.
Hi Caroline. I wanted to thank you too for this very valuable tutorial. I had no problems building a swift drawing app as an exercise. I am stuck for now with an Objective-C drawing engine in my main project. I cant seem to find a tutorial as in-depth as yours based in ObjC. Is there a reason for that? I wonder if you point me (semi-pun) in the right direction.
I don’t know of any modern tutorials being written in Objective-C - all tutorial sites that I can think of have moved to Swift.
www.raywenderlich.com has been going for years, so the older tutorials are written in Objective-C and they should come up with Google. Anything dated before June 2014.
Edit: The reason for no Objective-C is that Swift is the way forward. There will still be a large code-base of Objective-C apps, but companies are gradually switching to Swift. It’s faster to run (generally) and faster to code (once you know the language).
You are right of course. Time to change the engine to a swift based version. I hope the client will go for that. I’ll look through the tute list to see if something will make it easier. I do appreciate you getting back to me…
David
Hello Caroline. I have tried to implement this in my app, but it is not working as desired.
I am always getting zero value in “touch.force”.
Please help. Thanks…