No matter if modals are presented or the user performs any type of segue.
Is there a way to keep the button \"always on top\" (not the top of the screen) throughout
You can use the zPosition
property of the view's layer (it's a CALayer
object) to change the z-index of the view, also you need to add this button or your view as subview of your window not as subview of your any other viewcontrollers, its default value is 0. But you can change it like this:
yourButton.layer.zPosition = 1;
You need to import the QuartzCore framework to access the layer. Just add this line of code at the top of your implementation file.
#import "QuartzCore/QuartzCore.h"
Hope this helps.
Present it on this:
public static var topMostVC: UIViewController? {
var presentedVC = UIApplication.sharedApplication().keyWindow?.rootViewController
while let pVC = presentedVC?.presentedViewController {
presentedVC = pVC
}
if presentedVC == nil {
print("EZSwiftExtensions Error: You don't have any views set. You may be calling them in viewDidLoad. Try viewDidAppear instead.")
}
return presentedVC
}
topMostVC?.presentViewController(myAlertController, animated: true, completion: nil)
//or
let myView = UIView()
topMostVC?.view?.addSubview(myView)
These are included as a standard function in a project of mine: https://github.com/goktugyil/EZSwiftExtensions