ios access main window or view

user346443 picture user346443 · Jul 25, 2011 · Viewed 20.7k times · Source

I would like to know if there is a simple way to access the main window or view in IOS. Something similar to:

[UIScreen mainScreen]

Thank you.

Answer

user756245 picture user756245 · Jul 25, 2011

Try :

UIWindow *frontWindow = [[[UIApplication sharedApplication] windows]
                                                            lastObject];

or simply :

UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];