Skip to content

UIAlertController is hidden behind the shadow. #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Salmancs43 opened this issue May 4, 2017 · 5 comments
Closed

UIAlertController is hidden behind the shadow. #110

Salmancs43 opened this issue May 4, 2017 · 5 comments

Comments

@Salmancs43
Copy link

Hi When i present the UIAlertController it is showing behind the overlay. Is there any suggestion for that? Thanks
simulator screen shot may 4 2017 4 51 54 pm

@ephread
Copy link
Owner

ephread commented May 18, 2017

Hello @Salmancs43, sadly, nothing can be done at the moment. But there's hope, next version will ship with proper support of window levels.

@ephread
Copy link
Owner

ephread commented Jun 3, 2017

I've always believed that UIAlertController views were presented in their own window. Turns out I was mistaken. You're going to need to present the UIAlertController in its own window, which will sit above Instructions' window. By default, Instructions uses a window with the following level: UIWindowLevelNormal + 1 (it's customizable, but not yet in the README). The custom window will need to have an higher value than that.

Here's a possible way to achieve what, from the top of my head (untested).

let window = UIWindow(frame: UIScreen.main.bounds)
let dummyViewController = UIViewController()

dummyViewController.view.backgroundColor = UIColor.clear
window.rootViewController = dummyViewController
window.windowLevel = UIWindowLevelNormal + 2

// Instructions doesn't use a key window, but the alert probably should.
window.makeKeyAndVisible()

dummyViewController.present(alertViewController, animated: true, completion: nil)

After the alert is dismissed, we'll probably need to make sure that the key window is again the main window, and not the one used by Instructions. It's most likely done automatically, but I haven't checked.

@Salmancs43
Copy link
Author

    let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        alertWindow.makeKeyAndVisible()
        
        let alert = UIAlertController(title:"Please Select an Option", message:nil , preferredStyle: .actionSheet)
        
        alert.addAction(UIAlertAction(title: "Camera", style: .default , handler:{ (UIAlertAction)in
            print("User click Camera button")
            
            self.openCamera()
        }))
        
        alert.addAction(UIAlertAction(title: "Photo Library", style: .default , handler:{ (UIAlertAction)in
            print("User click Photo button")
            self.openGallary()
            
        }))
        alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.cancel, handler:{ (UIAlertAction)in
            print("User click Dismiss button")
            
            
        }))
        alertWindow.rootViewController?.present(alert, animated: true, completion: {
            print("completion block")
        })

It Can be achieved using this code.

@ephread
Copy link
Owner

ephread commented Jun 5, 2017

Problem solved!

@ephread ephread closed this as completed Jun 5, 2017
@kennenfromchina
Copy link

I've always believed that UIAlertController views were presented in their own window. Turns out I was mistaken. You're going to need to present the UIAlertController in its own window, which will sit above Instructions' window. By default, Instructions uses a window with the following level: UIWindowLevelNormal + 1 (it's customizable, but not yet in the README). The custom window will need to have an higher value than that.

Here's a possible way to achieve what, from the top of my head (untested).

let window = UIWindow(frame: UIScreen.main.bounds)
let dummyViewController = UIViewController()

dummyViewController.view.backgroundColor = UIColor.clear
window.rootViewController = dummyViewController
window.windowLevel = UIWindowLevelNormal + 2

// Instructions doesn't use a key window, but the alert probably should.
window.makeKeyAndVisible()

dummyViewController.present(alertViewController, animated: true, completion: nil)

After the alert is dismissed, we'll probably need to make sure that the key window is again the main window, and not the one used by Instructions. It's most likely done automatically, but I haven't checked.

perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants