Use UIview subview with SpriteKit - ios

So I am working on a simple SpriteKit ball and obstacle game. I have the zposition for the nodes set to 2 ( can be 1 but I set it to 2 to make sure it doesn’t interfere with anything else)
I am trying to add a background to it but instead of an image my I want to use a UIview as the background for my game. How should I use a uiview as a background for a SpriteKit scene. ?
The uiview I’m using is called Pastel. It’s a library that allows you to create animated gradient backgrounds like the Instagram app login screen.
I tried adjusting the position at
And I’ve even used the sendabove and sendbelow methods but they don’t work

In order for UIView with your background which is under SKView to become visible, you must set the allowsTransparency property of your SKView to true.
Edit:
you also need to set the SKView and the SKScene background color to clear – (thanks to Knight0fDragon)

Related

Disable rotation animation of one subview

I'm trying to disable device orientation animation for just some subviews in my UIView subclass. I managed to disable camera preview rotation animation by using this view layer as AVCaptureVideoPreviewLayer and reacting to UIApplicationWillChangeStatusBarOrientation by changing layer.connection.videoOrientation. This works ok, but I also have one subview added that I also want to rotate without animation. Is there some way I can remove this animation for just that subview? Also I can't use willAnimateRotationToInterfaceOrientation as it's in UIViewController, and I want my UIView subclass to work this way without implementing anything additional in the controller. I only have UIView functions and NotificationCenter to work with.

Add a UIView to SCNScene

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.

How to make view follow my image?

Im making a scene for my game. Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. (Im using a normal Viewcontroller).
In the game you are supposed to move an image to another image without colliding with obstacles. The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win.
But when my image moves, the view doesnt follow with my image. How do you do that?
I would be so thankful for any answear! Thanks.
I am assuming you are using SpriteKit yeah? The UIView size is not related to the scene size. So changing those will not make your scene any different.
To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
Scroll down to Example: Centering the Scene on a Node
Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around.
If you are targetting only iOS9 and above, you can use SKCameraNode and set:
SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = #"camNode";
self.camera = cameraNode;
Then you add your "character" (that is to be moved together with the camera) into the cameraNode. Then any movement, you need to move the cameraNode instead of the "character".

How to control Z-Order of UITableView in a SpriteKit scene?

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.

Touch Event clicking UIImageView while rotating

My ImageView rotates but while it rotates it doesn't recognize touches on itself.
Do you think it's okay if I create a button via code that's over the ImageView that recognizes the touch?
When an animation is applied on any UIView or any subclass object of a UIView like UIImageView, UIButton etc then it does not detect touch events because when an animation is applied to a view, the animated property changes to its end value right away. what you are actually seeing on screen is the presentation layer of your views layer.
To answer your question, Yes, you can make a UIButton that covers up the area of the UIImageView to detect touch events on it. That sounds like the easiest to implement option in this case.
Apart from that, this link may also help you in the process. Hit testing animating layers

Resources