Currently I have a UIView which contains some controls. I then have some images I programatically add to the view to display as animations. Currently at the end of each interval of my game loop im having to tell the controller to move the UIView control to the front, otherwise the images will appear on top of it. Is there a less costly method of making it persist as always on top.
Currently I have the following at the end of my game loop:
[self.view bringSubviewToFront:myControlView];
Could I do something like this when the game initiates:
myControlView.alwaysOnTop = true;
Objective-C
Swift 2
Swift 3
This solution is better, especially if you want your view to be always on top, regardless of other views added after it. Just add any other view using
addSubview:
and it will always remains on top.to make a subview move to the back of all other current subviews, use
view.sendSubviewToBack(yourSubview)
.Rather than using
-addSubview:
to insert your images, use-insertSubview:belowSubview:
and pass yourUIView
as the second parameter:Note that for similar purposes you also have access to the methods
-insertSubview:aboveSubview:
and-insertSubview:atIndex:
.The other option is to place your view on another UIWindow with higher windowLevel. Learn from Flipboard FLEX or my simplified Paramount
Take a look at the FLEXWindow on how to choose proper windowLevel and handle touch