Is it posible to insert a UITextView (or other UIKit view) into an augmented reality SCNScene? - ios

Weird crazy question I know. My current setup is a SCNScene with a camera controlled by the device's gyroscope. I'm able to add and light normal nodes, however I would like to add 2D UIView objects into the scene like UITextViews or maybe some buttons. The views would need to be inside the scene and thus become no longer visible if the camera moves away from them.
Firstly, is this even possible? Or would this be way more difficult to implement than rebuilding an editable textview as a node? Could this be achieved by categories or...?

I just talked to the scenekit people here at WWDC. He said that as of now it is completly impossible to do it in a nice, functional way. The only options he offered as a possible solution is to create the UIView element somewhere off screen or behind the scene and continuously take screenshots of the object and apply those images as a texture to a SCNNode. He also pointed out the performance will be very poor with this because taking screenshots is heavy and you can't get going very quick with it. So I guess this is a no-go until UIView adds support because, according to the engineer, it's impossible to implement this because of a UIView limitation and not a SceneKit one.

Related

Draw above UIWebView in Swift

I'm looking for a way to draw "Lines" above a UIWebView.
I have a UIWebView that display a PDF file, the user should be able to add "Lines" and "Sketches" (simple one color lines etc) for sure this could be done with a UIView on top of the UIWebView but i m running into 2 logical problems.
First can the UIView where the drawing is, be transparent beside the lines - so you can view the pdf through it?
How could i handle the zooming in the PDF, if a user zoom the WebView, the UIView have to zoom "with each other" - so the drawing stays at the same spot/zoom level?
Is there any other way to display a PDF and add drawings/annotations to it? Currently i m using a QLPreviewController where i see no way to add any kind of annotations?
Is three any best practice for this?
PSPDFKit handles this (and many other hard PDF problems) very well. Using a web view for this kind of problem is likely to have many little corner cases. Any commercial product that has non-trivial needs around PDFs should definitely start there. For open source projects I don't have a great answer beyond "yeah, PDFs are a pretty tough; good luck."
That said, here are some starting points that may help you.
You can turn off zooming with webView.scalesPageToFit = false
You can get the current zoom scale using webView.scrollView.zoomScale
I believe you can KVO observe zoomScale to track it while it changes, but you may only get the target value (which will cause you to lag).
You can disable zooming (scalesPageToFit) and then re-implement it yourself with a UIPinchGestureRecognizer and scrollView.setZoomScale(_:animated:). That way you could track the zoom changes better. You could also try to handle the animation yourself with a CABasicAnimation so that you could keep it in sync.
My experience with scroll views, web views, and PDF is that there are a lot of little funny interactions that will surprise you. Getting something that "kind of" works isn't that hard, but getting it really clean, smooth, and beautiful can be a nightmare. That's why I typically recommend PSPDFKit to clients. You'll generally spend much less on the license than on the custom development.

Is there a way to overlay frames in SpriteKit?

As the title states, is there a way to stop the canvas / SKScene from clearing the contents of the current frame, and just draw over the current frame? Now the contents of the scene/frame are cleared every update cycle, i would like to just draw over the previous frame.
I have worked with OpenFrameworks and other visual programming frameworks, and the way it worked there was; you draw stuff on the update call, on the next update call you set a background again to 'clear' the previous frame.
I have looked through the whole documentation of SpriteKit and couldn't find anything. I also tried to emulate the effect by pushing more nodes onto the scene, having them follow one step behind the 'new' nodes. This was, as i expected, way to heavy on CPU / RAM.
No code, i know, i'm sorry, but the stuff i use is pretty basic. Any one of you have any thoughts on this?
Hope to hear from you, thanks.
You should be able to do this by setting the clearsContextBeforeDrawing property on your SKView to NO.
clearsContextBeforeDrawing is a property of UIView, which SKView is a subclass of.
I wouldn't consider this to technically be Sprite Kit providing the behavior, but I believe it's what you're looking for.
Note: I didn't actually test this, so it's possibly that this won't actually work. It would theoretically work perfectly for UIKit.

UIView Animation like Periscope app

I want to re-create the animation that exists in the "Periscope" app.
In the app the user presses the screen and small hearts goes from the button right of the screen half way the the top and disappears from the screen.
I was wondering what would be the most efficient way of implementing this?
UIView animations / UIKit Dynamics / CABasicAnimation?
This is a screen shot from the app
Thanks,
You could create such an effect quite easily with particles in SpriteKit. It's exactly designed for creating such effects, especially in games, but it is also usable in normal apps. The interesting class is SKEmitterNode.
The official doc is here:
https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKEmitterNode_Ref/index.html
Since UIKit Dynamics is a physics engine which is integrated to the UIkit it provides a option to create interface that feel real by adding behaviors such as gravity, attachments (springs) and forces. Also you can define the physical traits that you would like your interface elements to adopt. Where as UIView has most powerful animatable property which takes a CGAFFineTransform. This is a matrix that expresses how each pixel of the UIView should be modified, applying some math formulas.
Pl. check the below links, which has very good examples of UIKit dynamics and Animation and what features can be acheived. I feel it might be good option to use UIKit dynamics because of the flexibility it provides. http://www.sitepoint.com/using-uikit-dynamics-swift-animate-apps/
http://www.bignerdranch.com/blog/uidynamics-in-swift/
http://mathewsanders.com/prototyping-iOS-iPhone-iPad-animations-in-swift/

Animating a "character" within iOS app that's not SpriteKit

I am in talks with a client to do an app, but in it, they are wanting it to revolve around a little character that follows you throughout the app (think Clippy, from the old days of Microsoft Word :)).
One thought I had was, can I use an SKSprite/Node inside an iOS app not using the SpriteKit framework?
Or is this a matter of animating through an array of UIImages?
Those were my first thoughts - does anyone know the best direction to go in for something like this? I need basic animations for a character throughout the whole app.
Depending on the detail of animation needed, you could do it with just CoreAnimation and possibly selectively choosing the image to display in an UIImageView. For example, see the answers to this question: rotate a UIView around its center but several times
Simple answer is, No, out of the box you can't use a class from a framework and choose to not use the framework. Though I'm not exactly sure what that question means. An SKSpriteNode renders via an SKScene node, and an SKScene node renders via an SKView, which is rendered by a View Controller.
You could do something fancy like dedicate the SKView as only part of the screen, and have a standard UIKit view as the other part, or only have the SKView appear on the screen when you needed it I guess.

scrolling and pan/zoom in single scene cocos2D

I am currently working on my first IOS app and have sort of hit a 'brick wall' if you will. I am using Cocos2D for most of my graphical interface do to my preference and ease when working with chipmunk.
Currently I am trying to create a scene that has at least 2 layers displayed at once, split screen style. One layer I need to be a vertical scrolling menu, while the other layer I need to be a pan/zoom 'map' type layer. Being the noob that I am when it comes to Objective-C and Cocos2D I can not seem to figure out how to even attempt this. I have done some searching and came across the extensions for Cocos2D which offer the pan/zoom layer.
Any help or pointers to tutorials, references, sites, etc. would be greatly appreciated!

Resources