Apple's SpeedSketch example app is very laggy - ios

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.

Related

Does Apple's PencilKit support that Drawing and Holding to Create Perfect Shapes, if not, how to implement it?

What I want:
The picture is from Notes app in iPad. The blurred red path I drew with Apple Pencil. Holding and then the perfect circle shape generated.
I checked the Apple's developer documentation about PencilKit. It seems no related API to support it.
But apple's Notes app of the system in iPad can do it. Does it mean that Apple have not opened the relevant API? However, I really need to implement Drawing and Holding to Create Perfect Shapes in our app. How to do it?
The only thing I can think of is to use coreML to reshape pencil path? I know very little about it.

Best approach for coding a painting app on iOS / iPad

I’m trying to build a drawing/painting app for the iPad, with textured brush tips and paper.
So far, all drawing app example codes I've come across seem to work by stroking a path. However, I'd like to actually apply a texture all along the path, to simulate say, an oil brush, or charcoal.
Here is an example of a brush tip texture: Bursh tip
The result when painting with the same brush tip: Result
In the results, the top output is what it looks like when the "brush tip" texture is applied far apart along the path.
The bottom result is the texture applied with very small steps along the path. Those who've worked in Photoshop with custom brushes will find this familiar.
I had once prototyped this in Processing years ago (I've since lost the source code), and got it to work in real-time.
In Processing, I converted both the brush tip PNG and the canvas (or the image I'm painting on to) into an array of integers. Then, I simply copied the values from the brush tip to the canvas texture, at the appropriate index. At the end of the cycle, I displayed the image, for that time-step. Repeat this dozens of times in-between each point returned by the mouse.
How would I approach this in iOS, and in real-time? I tried this (https://blog.avenuecode.com/how-to-use-uikit-for-low-level-image-processing-in-swift) but it's way too slow.
This makes me believe Metal might be the only way forward. Is that true, or am complicating this unnecessarily?
Thank you for any guidance!
PS. I'm coding in Swift 5, targeting iOS 13, in Xcode 11.5.
Welcome!
I recommend you check out Core Image. It's Apple's framework for image processing (on a higher level than Metal, though it can integrate with Metal). Unfortunately, the documentation is a bit out-dated, but I'm sure you can translate it into Swift.
Here Apple describes how you would realize a painting app with Core Image and here you can download the corresponding sample project.

How to reproduce watchOS closing activity ring animation with sparks on iOS?

How to best reproduce the closing activity ring animation from watchOS 4 on iOS? Im particularly interested in the rotating sparkling effect.
Here a still frame of the animation I'm talking about:
and here is a video of it.
Is it possible to implement something like this with Core Animation?
Here at the university of science in zürich in the usability lab, we use:
sketch or illustrator or designer.gravit.io for designing the svg sketches.
than we import it in after effects or in Haiku.ai for animating
and export it as .json for airbnbs animations library Bodymovin or also known as Lottie. Therefor are libraries for web, android and ios available.
The advantage of this solution over #bryanjclark "exported it as a series of images" is that the animation is sharp in every resolution (svg), it is only one .json file and you have the full control over its speed and frames.
Otherwise if you really want to do it with code only, give a look at this Article, done with OpenGL ES2.0.
Or with the AnimationCore example in this SO Answer.
I’m nearly-certain that is a pre-rendered animation, not something generated on-device. (If it is generated on-device, it’s not something you’d have API access).
I’d bet that:
a designer worked it up in a tool like AfterEffects,
exported it as a series of images,
then the developers implemented it using something like WKImageAnimatable
You can see other developers using WKImageAnimatable to build gorgeous animations in their WatchKit apps - for example, Cultured Code’s app Things (watch the video there!) has some really terrific little animation flourishes that (almost-definitely) use WKImageAnimatable under-the-hood!

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.

2013, Existing package for drawing (painting, brush, lines) in 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.

Resources