Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 480 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add a UIView above all, even the navigation bar

#11
Here is a simple elegant solution that is working for me. You can set the z position of the navigation bar to below the view:

self.navigationController.navigationBar.layer.zPosition = -1;

Just remember to set it back to 0 when done.
Reply

#12
**Note if you want add view in Full screen then only use below code**

Add these **extension** of **UIViewController**

public extension UIViewController {
internal func makeViewAsFullScreen() {
var viewFrame:CGRect = self.view.frame
if viewFrame.origin.y > 0 || viewFrame.origin.x > 0 {
self.view.frame = UIScreen.main.bounds
}
}
}

Continue as normal adding process of subview

Now use in adding **UIViewController's viewDidAppear**

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

self.makeViewAsFullScreen()
}
Reply

#13
UIApplication.shared.keyWindow?.insertSubview(yourView, at: 1)

This method works with xcode 9.4 , iOS 11.4
Reply

#14
@Nam's answer works great if you just want to display your custom view **but if your custom view needs user interaction you need to disable interaction for the `navigationBar`**.

self.navigationController.navigationBar.layer.zPosition = -1
self.navigationController.navigationBar.isUserInteractionEnabled = false

Like said in Nam's answer don't forget to reverse these changes:

self.navigationController.navigationBar.layer.zPosition = 0
self.navigationController.navigationBar.isUserInteractionEnabled = true

<hr>
You can do this in a better way with an extension:

extension UINavigationBar {
func toggle() {
if self.layer.zPosition == -1 {
self.layer.zPosition = 0
self.isUserInteractionEnabled = true
} else {
self.layer.zPosition = -1
self.isUserInteractionEnabled = false
}
}
}

And simply use it like this:

self.navigationController.navigationBar.toggle()
Reply

#15
Swift versions for the checked response :

**Swift 4 :**

let view = UIView()
view.frame = UIApplication.shared.keyWindow!.frame
UIApplication.shared.keyWindow!.addSubview(view)

**Swift 3.1 :**

let view = UIView()
view.frame = UIApplication.sharedApplication().keyWindow!.frame
UIApplication.sharedApplication().keyWindow!.addSubview(view)
Reply

#16
You need to add a subview to the first window with the UITextEffectsWindow type. To the first, because custom keyboards add their UITextEffectsWindow, and if you add a subview to it this won't work correctly.
Also, you cannot add a subview to the last window because the keyboard, for example, is also a window and you can`t present from the keyboard window.
So the best solution I found is to add subview (or even push view controller) to the first window with UITextEffectsWindow type, this window covers accessory view, navbar - everything.

```
let myView = MyView()
myView.frame = UIScreen.main.bounds

guard let textEffectsWindow = NSClassFromString("UITextEffectsWindow") else { return }
let window = UIApplication.shared.windows.first { window in
window.isKind(of: textEffectsWindow)
}
window?.rootViewController?.view.addSubview(myView)
```
Reply

#17
You can do that by adding your view directly to the keyWindow:

UIView *myView = /* <- Your custom view */;
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
[currentWindow addSubview:myView];

**UPDATE -- For Swift 4.1 and above**

let currentWindow: UIWindow? = UIApplication.shared.keyWindow
currentWindow?.addSubview(myView)

**UPDATE for iOS13 and above**

`keyWindow` is deprecated. You should use the following:

```swift
UIApplication.shared.windows.first(where: { $0.isKeyWindow })?.addSubview(myView)
```
Reply

#18
In Swift 4.2 and Xcode 10

var spinnerView: UIView? //This is your view

spinnerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
//Based on your requirement change width and height like self.view.bounds.size.width
spinnerView?.backgroundColor = UIColor.black.withAlphaComponent(0.6)
// self.view.addSubview(spinnerView)
let currentWindow: UIWindow? = UIApplication.shared.keyWindow
currentWindow?.addSubview(spinnerView!)

In **Objective C**

UIView *spinnerView;//This is your view

self.spinnerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)];
//Based on your requirement change width and height like self.view.bounds.size.width
self.spinnerView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
// [self.view addSubview:self.spinnerView];
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
[currentWindow addSubview:self.spinnerView];


This can work either Portrait OR Landscape mode.

One more simple code is:

yourViewName.layer.zPosition = 1//Change your view name
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through