user2210889
user2210889

Reputation: 123

Keep UIView alway on top in app?

Is it possible to keep a UIView on top of everything else in an app, even modals etc.?

Could it be done by having two UIWindows maybe or is there a recommended way of doing this?

Upvotes: 4

Views: 3407

Answers (2)

MaheshShanbhag
MaheshShanbhag

Reputation: 1494

You can have 2 windows in an application. But it is simply not recommended and we should avoid using multiple windows if we can. You can add a view on top of everything as a subview of the UIWindow as follows

[[UIApplication sharedApplication].keyWindow addSubview:viewName];

which should be not use often but you can have a view at the top of the view hierarchy by bringing it to the front as

[self.view bringSubviewToFront:viewName];

which brings the view to the front.

Upvotes: 3

Pei
Pei

Reputation: 11643

Try to add that view to the keyWindow of your application. And then bring that view in front of keyWindow. So...

[UIApplication sharedApplication].keyWindow addSubview:yourView];

// your code here
[UIApplication sharedApplication].keyWindow bringSubviewToFront:yourView];

Upvotes: 1

Related Questions