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'.
Related
Is it possible to check if an AVPlayerLayer which is added as a sublayer to a ViewController's subview's layer is visible or not? Basically if at any point of time, another view be laid over the said subview, I require to pause the AVPlayer, even if it is obscured partially. Note that I set the zPosition of the AVPlayerLayer to -1 when adding it as a sublayer. The implementation is in a framework that I'm working on so I have no control if the end developer puts another subview over the subview or inside the subview that contains the AVPlayerLayer.
Some things to consider are that someone(end developer using my framework) could:
Add multiple subviews over the the subview or inside the subview with my player
Add a sublayer to the subview with my player, thus obscuring the player
Any help is appreciated.
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.
I have a UIView for CorePlot and I want to add UIView under the plot as a subview. I have tried this:
[self.view bringSubviewToFront:_viewTable];
But it doesnt work. How can I make it work?
EDIT:
My Storyboard:
Green - firstPieChartView (CorePlot view)
Red - UIview with tableView
In viewDidLoad:
[self.firstPieChartView addSubview:_viewTable];
[self.firstPieChartView bringSubviewToFront:_viewTable];
Do not add subviews to a Core Plot hosting view. The iOS hosting view applies a flip transform to its children so Core Plot can share drawing code with the Mac version. Instead of making your view a subview of the hosting view, make them siblings (i.e., children of the same parent view).
You are bringing the view to front by this, not adding it as a subview. First you have to use:
[self.view addSubview:yourSubview];
--in order to add it. Then you can bring it to front, if you're overlaying it with other subviews.
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.
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).