2013, Existing package for drawing (painting, brush, lines) in iOS? - ios

I need to add typical finger drawing to an app.
(The usual.... choose colors, erase, thickness - just the usual you see in every app made.)
It's hard to believe I have to program this from scratch, in this day and age?
It's hard to believe there is not a common solution for this?
All I could find is...
https://github.com/levinunnink/Smooth-Line-View
Review: that is a (beautifully written) example fragment of a few lines of code being how to draw with a path, with a good smooth result. It works perfectly, but it's just for drawing one "path." For example, you can't make a drawing with more than one color. there is no undo or anything like that. (See also note on the fourth review item here regarding path-math.)
https://github.com/sumanthk2006/Smooth-Line-View-1 (variation of above, but does not run under ARC, unfortunately demo does not properly launch etc)
Review: this is "abandonedware" or maybe "frustrationware" :) It does not run and is not ARC-ready. It is a seemingly well-written class that claims to do undo, colors, erase, etc. It even has a proper delegate to track your button states. But it doesn't work.
UPDATE Regarding this paackage. As a matter of fact, if you massage it it works well. Suggest (i) throw away the example app files. (ii) using modern Xcode, use the "convert to ARC project" feature on the two main files. There are a coupe little problems like it should use awakeFromNib. If you get it working it actually does everything, really well.
THERE ARE SERIOUS BUGS in SmoothLineView1. just to be clear, it suffers some serious bugs - you'll see there's a "streaking" effect when you draw.
http://www.cdframeworks.com/product/brushengine
Review: This commercial package (under $100) is well made and email support is fast. Unfortunately it does not have undo so it's not suitable for many situations. (Also does not have erase.)
Mentioned below is this popular article:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/
Review: this is a good article on the actual TECHNOLOGY of drawing curves, on the let's say "path-math". Unfortunately it's no help at all if you need a working, ready to use, drawing package (with the obvious features, undo, erase, colors etc) to use in an iOS app. Thus for example, whatever actual solution you were using, you may, perhaps, want to apply the math concepts in this article.
I appreciate that the basic concepts are very simple, it's easy enough to "start from scratch". But it's just - ridiculous - to have to do from scratch for something so commonplace. Is there a solid package I'm missing?
It's fairly amazing that the four scratchy references above are the only things out there.
Any ideas? What's the best package today (late 2013) for adding drawing to an iOS app? THANKS.

As of 2017, I use https://github.com/acerbetti/ACEDrawingView/.
It can be used through cocoa pods, and provide full functionality over integrating a drawing feature in your app (color, brush, size, eraser, undo/redo/, etc).

http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_freehand-drawing/ has a good, clear tutorial on smooth freehand drawing on the ios. If you just follow the tutorial, you can implement it easily into whatever app you are trying to make. It has stuff about increasing line quality and smoothness, and stroke quality.http://www.raywenderlich.com/18840/ is another tutorial on a simple drawing app, self-contained. You can combine aspects of both to get what you want.
edit: https://developer.apple.com/library/ios/samplecode/GLPaint/Introduction/Intro.html is the GLPaint sample provided by apple, which includes detecting shake. I thought it seemed more official, since it's from apple
to answer your question, there is no package for drawing directly, but there is a UIKit class, UIBezierPath, that lets you draw shapes made of straight lines or some curves.

Related

Apple's SpeedSketch example app is very laggy

I want to create an app which uses the Apple Pencil (or just a finger) to draw/sketch/write on a blank "sheet" on the iPad. Last WWDC there was a session which shows how the Apple Pencil should be used inside an app.
Here's a link to this session: https://developer.apple.com/videos/play/wwdc2016/220/
(You can download the example app there.)
When you start to draw something it works really great. But after a while, if you have drawn a lot, it gets really laggy and I don't know why. I want to use this code inside my app to be able to use the pencil, but I can't use it like that, because it get's really annoying when you want to draw something and it takes some time until the line is showing up.
There is the following comment in CGDrawingEngine.swift:
/**
Note: this is not a particularily efficient way to draw a great stroke path
with CoreGraphics. It is just a way to produce an interesting looking result.
For a real world example you would reuse and cache CGPaths and draw longer
paths instead of an aweful lot of tiny ones, etc. You would also respect the
draw rect to cull your draw requests. And you would use bezier paths to
interpolate between the points to get a smooother curve.
*/
It would be very nice if you could try to understand what's exactly happening and why it is very slow after some time and how to change the code according to Apple's comment on the drawing function.
(PS: I should mention that this example app is only running on iOS10 Beta with Swift 3.0)
EDIT: I'm testing this app on an iPad Pro (12.9") with iOS10 Beta 5.

How to check intersection of two images that aren't rectangular?

New user to the site, but I have used it in the past so I felt it best to ask my question here, for the best chance of getting a response.
What I'm dealing with is one object, this being the sprite for my latest app, which I need to check for when it comes in to contact with another object, in this case, a tunnel which will curve.
Now, I'm aware of CGRectIntersectsRect, however I can't see that being helpful, as if I've got 2 UIImages, that being the top and bottom of a "mountain", and said pieces curving, there's no doubt that the sprite would touch the "rectangle".
What I need is something to trigger when the sprite hits the actual wall, however my limited knowledge of Objective-C isn't helping my case.
I imagine someone out there will know what I can do to resolve this, as for all I know it could be a simple solution.
Thank you in advance everyone!
First, I'd probably not build these basic pieces yourself. For iOS 7, you can use SpriteKit, which is built-in. If you want to support older versions of iOS, look at cocos2d (it's good for iOS 7, too).
But to the question, one approach for detecting arbitrary overlaps is to draw both objects into a buffer and check if there are any overlapping pixels (for instance, by drawing one in in pure red, and another in pure green, and then looking for pixels that have both). For a discussion of how to do this kind of thing in Core Graphics, see Clipping a CGRect to a CGPath, which provides sample code for the simplest version (checking for the intersection of a rectangle and curve), but the same approach can be used more generally. Note that this drawing can get expensive if you're doing it constantly, so usually you first check whether the bounding rectangles overlap. That tells you whether it's even worth the trouble to look closer.
But first I'd look at SpriteKit.

Cool bubble effect using something like CCParticle in Cocos2d (no third party tools)

I would like to achieve a cool particle effect like in here.
The bubble should be similar to an explosion starting from the centre and expanding. I'd like to add an animated wave coming out from the left and right side of the bubble and looking like this. I guess I could use to two distinct animation and put together as I assume this has never been done in a Cocos2d game.
Also, I would like to avoid using non-Cocos2d tools as particle designer. In chapter 1 of the Cocos2d cookbook I found some cool particle examples and the code doesn't seem too complex. Instead, using third party tools I need to import their classes and use their file format to create particles and I have to pay. Even more there doesn't seem to be many particle effect files shared (at least not the ones I want).
Thanks a lot.
EDIT: I added a comment with a theory on how the first of the two animation could work.
Your best chance is with Particle Designer. You can modify the emitters in the library and visualize your changes. It's the easiest way to achieve a great effect. Once you find the combination of values that you like , you can simply create an emitter from code and set all those properties yourself. You don't have to pay or use any class (which you actually don't have to , it's already built in cocos2D) . So just download the free version of Particle Designer and then set the values from code. It's the same thing , it only takes a bit more work to do.

OpenGL on Mac OS X for an iPhone developer

I'm looking for a good example of a basic OpenGL App for Mac OS X, but not too simple.
I have a good solid base of experience with iOS and objective-c, but I've never built a Mac OS X App.
All I've been able to find are super simple examples that do all the drawing and logic in drawRect: or overly complex examples with layers and layers of abstraction. I don't want to use Glut, SDL, or any other 3rd party libs or engines.
I want to be able to drive a Game Loop and use CADisplayLink like I do on my iOS games. I'd also rather not use .xib files because I like to understand what's going on and having that black box there hides too much for me, although I'd be happy to use it as a first step if it got me everything else (game loop, CADisplayLink, etc).
My iOS code creates it's OpenGL Views by hand, but there seems to be enough of a difference between iOS and OS X that I'm having trouble making heads or tails of it. I just need to get a Window and an OpenGL view and be able to draw to that via the game loop.
Can someone point me to a good resource? The Apples examples jump between to simple and too complex as does everything else I can find on the Internet.
Sorry I can't answer to your questions. I always did use XIB files (a looong time ago, I too always wanted to re-invent the wheel, but now I'm lazy and prefer getting stuff done :p) and I never used display links.
What don't you like about overriding drawRect: ?
And the sample I used to get started with OpenGL was this one : http://developer.apple.com/library/mac/#samplecode/CocoaGL/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004501
Not too complicated, and simple enough to understand it (and it doesn't use any XIB, if I remember well :p)

Animated 2d Map Desktop Widget

I need to animate some vector icons smoothly moving about a 2d map. I have time-lat/lng pairs forming tracks. Down the road I would really like to be able to convey various GIS data like topography and roads on the map along with my smoothly animated icons.
Any suggestions on what to use? I find things like Quantum GIS but it seems geared to generating static maps. I've tried messing around with KML but I cannot find any way to make things move smoothly: marker icons clearly bounce along the waypoints even when I space them very closely.
EDIT: clarified I'm interested in a desktop widget
Animation options are limited in GIS as far as I am aware.
ESRI's ArcObjects could be used to create animations - see this chapter in the online help:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=An_overview_of_animation
and these examples (however none have vectors moving around):
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Sample_animation_videos
ESRI software is expensive to purchase, and users would also need the software if you wanted to provide more than an exported video.
You are probably best working with WPF (is this widget for Windows?), Silverlight, or Flash. ESRI have a Silverlight example here:
http://www.codeproject.com/KB/showcase/GIS_Silverlight.aspx
There is also the following collection of WPF classes for the OpenSource SharpMap:
http://wpfsharpmapcontrols.codeplex.com/
However it seems very much in beta at this stage.
Alternatively it may be easier to use GIS software solely to provide a background image, and do all the animation elsewhere.
I would say, try this animation code for Google Earth; however, try emailing the osgeo or qgis userlists and they'll guide you

Resources