mossy
mossy

Reputation: 39

custom window gets removed when closing app

I am creating an app that has two windows, it works like: when I click the button, the second window shows up and takes over the screen. When I hit the close button(on the second window), the second window dismiss from screen.

The issue is like this: when it is displaying the second window, I double click the home button to get out of the app, the app jumps to display the first window(the original one), and after I come back to the app, it still display the first window, but the key window is the second one, so all the hit events still goes to the second window. It makes my app looks frozen, unless I click the place where the "close" button is, the app goes back to normal.

Did anyone experience this? I cannot figure out what create this issue, it looks like the system switching the windows.

It doesn't happen every time I get in and out of the app, it happens occasionally.

Upvotes: 2

Views: 138

Answers (3)

Jose Ibanez
Jose Ibanez

Reputation: 3345

You may also want to look at the windowLevel property on UIWindow.

Levels are ordered so that each level groups windows within it in front of those in all preceding groups. For example, alert windows appear in front of all normal-level windows. When a window enters a new level, it’s ordered in front of all its peers in that level. See “UIWindowLevel” for a list of possible values. The default value is 0.0.

I had an app that used two windows to display a transparent window floating above a video player. Alert views use elevated window levels to present themselves, so I would make the background window's level -1.0, and the active window's level 0.0.

Upvotes: 0

mossy
mossy

Reputation: 39

So I didn't figure out what to do with the problem, but I have a alternative solution. That is display the second window by secondWindow.hidden = NO; instead of [secondWindow makeKeyAndVisible];

In this way, it will solve a lot of other problems, too(like the key window issues when passing the hit to the first window, or there is a new window, like an alert view or modal view comes up), as it still let the system handle the key window assigning task rather than grab the control in our hand.

Hope this will also help others who meet the same problem. :)

Upvotes: 1

Ismael
Ismael

Reputation: 3937

You can either try to [currentWindow makeKeyAndVisible]; again, or you can change your design and simply work with a modal view controller instead of a whole new window

Upvotes: 0

Related Questions