开发者

ios access main window or view

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

开发者_StackOverflow
[UIScreen mainScreen]

Thank you.


Try :

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

or simply :

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


The main window is best found using UIWindow * mainWindow = [UIApplication sharedApplication].windows.firstObject;

Using keyWindow can return a keyboard or UIAlertView window, which lie above your application window.


If you have a pointer to some subview in the window, you can easily access its window:

UIWindow *window = mySubview.window;


Simply clever, works from any class:

[(YourAppDelegate *)[[UIApplication sharedApplication] delegate] window];

Note: don't forget to import your appDelegate class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜