I have a UIScrollView added onto as a subview from within the SKScene. The code is running perfectly but I am unable to fix its Z position relative to some of the SKSpriteNode existing on the main SKScene view. Is there any way this can be done. By adding the UIScrollView as a subview, its completely over the top of any other SKSpriteNodes on my scene.
Please help me out!
This can't be done. All elements inside a SKView are, well, part of the SKView. Any other view can only be in front of or behind the SKView.
Related
Is it possible to add a UIView to a SceneKit SCNScene?
I have a need where I want a collectionview in the mid ground with some SCNNodes in front and behind.
I can get it working with a hack by screen-shotting the collectionview every-frame and then rendering this as a texture on a node, but it's very slow.
Any other ways around it?
No the is no standard way to bring a uiview in mid of scnnodes.
Try to stack a skscene to diffuse contents in your scnnode.
After that bring a uiview to the skscene.
I have a SKScene in which i have bunch of sprites and physic stuff. I needed to add UIView to SKView who presented the scene. Now i need to put some SKNode over UIView. But when I add child to my scene, UIView is displayed at top, and newly added nodes stays below. Is it possible to show newly added nodes over UIView components ?
The short answer is no.
You already have a UIView which you can access in the view from didMoveToView:(SKView *)view. All nodes reside in that view. If you add another view, it either goes in front or behind the 'SKView'.
So I'm trying to let the user two-finger scroll a SKView that they can paint on. I'm using a PanGestureRecognizer that is set with a minimum number of fingers as 2. I have the selector it calls shift the offset of the UIScrollView to which the SKView has been added. It scrolls the SKView perfectly... the problem is any SKNodes that have been added to that view don't scroll with it. Since a picture is worth a thousand words hopeful these will help(Thanks for any help you can give! I'm sure there is a simple solution. I just haven't found it ^^; ):
Initial state
After Scrolling the view up
After Scrolling the view down
UPDATE:
I added a contentOffset variable to the "GameScene" that, moved all SKNodes to a "root" node and then have this in the update run root.position = self.contentOffset and this does in fact get the nodes scrolling as well... however, if I start off with a screen that looks like this:
If I then scroll up and down a bit and then add a new node by touching at the very top edge in the center then I get a screen that looks like this:
So as you can see when I scroll the nodes will "slide" a bit and this also shifts the way the touches are registered as well. Also, it doesn't seem to "slide" again after that.
It may help at this point to know that I add a physicsbody to each of the added SKNodes so that I can hit them with touches but set the dynamic = false so theoretically should only be moved if explicitly told to. So any ideas on this?
I have an iOS SpriteKit SKScene that contains a UIKit UITableView as part of the scene via View.AddSubview. Generally this works fine. I then create an SKNode that temporarily sits on top of the scene (to zoom in on a particular image) and I want it to be at the top of the z-order, so I set ZPosition of the new node to 999 arbitrarily. When the node is added, it appears on top of all the other SpriteKit nodes, but the UITableView is still at the top of the z-order and still accepts input even though there is a sprite node on top of it (supposedly).
Is there a way to set the z-order of a UIKit view when it is hosted on a SpriteKit scene so I can push it backwards?
Thanks for any suggestions.
This is not possible. Any UIView added to the SKView sits on top of everything rendered by the SKView. Nodes rendered by SKView and the SKScene itself aren't views, they are elements inside the SKView much like table cells are part of UITableView, but you can only change the draw order of the UITableView and the SKView. You can't take individual elements (nodes or cells) and draw them outside their container views.
The same issue exists in other 2d renderers by the way, be it cocos2d or plain OpenGL.
Basically, I'm working on an app on the iPad that involves a line which the user can scroll horizontally through on the screen. It's set up so that there is a UIScrollView and a UIView on top that uses drawRect. I also have a UIView that's basically a ball which I can move around via touch, and also detects when it is within the UIScrollView and when it is on the line that is painted in the UIView.
Here's my main problem, though. Both the UIScrollView and the ball are subviews to the same view controller, and I want to make it so that, when the ball is dragged into the UIScrollView, that it will scroll along with it and even disappear if need be. How should I do this? should I just make the ball a subview of the UIScrollView when this happens, or should I do it some other way?
Use a container view. Put the ball in the transparent container subview and that is the view that moves around ( taking the ball with it). When you want the scroll view or line to move with the ball, insert them into the container at position 0 (under the ball).