1

I currently have a particle view connected to storyboard. The problem that I'm facing is that I'm displaying an alert at the same time I show this view, and the alert is always shown in front of the particle view. Is there a way where I can always place the particle view in front? I'm using a third party alert library titled SIAlertView, so I'm assuming it may be possible.

I've logged the zPosition of the alertView and it's always 0, so I set the zPosition of my particle view's layer to 10, but it is still shown beneath the alert view.

Here's the storyboard hierarchy:

enter image description here

iDev
  • 1,042
  • 13
  • 19
KingPolygon
  • 4,753
  • 7
  • 43
  • 72
  • I am not sure but what do you mean about z index, but there are few another concept to work with depth in iOS. Check this link http://stackoverflow.com/questions/4631878/how-to-set-iphone-ui-view-z-index you should put subview to top or above another view, it will work I think – Matrosov Oleksandr Apr 18 '14 at 08:02
  • Thi has nothing to with z-index. It's the `windowLevel` of the `UIAlertView` that keeps everything behind – n00bProgrammer Apr 18 '14 at 08:21
  • I think you might be correct. I logged the alertView's superview, and did get UIWindow. – KingPolygon Apr 18 '14 at 08:24

1 Answers1

1

I do not know about SIAlertView but normal UIAlertView is shown via separate window. If you want to overlap it you can not do it by changing zpozition, you have to also use a separate window:

// do not forget to keep strong reference for it somewhere!
UIWindow *notificationWindow; 

//your frame here!
notificationWindow = [[UIWindow alloc] initWithFrame: some_cgrect];

notificationWindow.backgroundColor = [UIColor clearColor]; // your color if needed
notificationWindow.userInteractionEnabled = NO; // if needed

// IMPORTANT PART!
notificationWindow.windowLevel = UIWindowLevelAlert + 1; 

notificationWindow.rootViewController = [UIViewController new];
notificationWindow.hidden = NO; // This is also important!

UPDATE:

To overlap also a status bar use

notificationWindow.windowLevel = UIWindowLevelStatusBar;

to dismiss UIWindow just invalidate strong pointer to it. Something like:

self.strongPointerToYourWindow = nil;
Avt
  • 16,927
  • 4
  • 52
  • 72
  • Thank you Avt? I tried this and added my particleView as a subview to this and it worked like a charm! My question now is, how do I remove it once I'm done calling my method? I have a method that I call where I create this notificationWindow and start my particle animation. – KingPolygon Apr 18 '14 at 08:44
  • BTW How would I also hide the status bar? With the addition of this code, the status bar is no longer hidden. – KingPolygon Apr 18 '14 at 08:51
  • I have updated the answer. Please check. If answer was useful please upvote/accept it! – Avt Apr 18 '14 at 09:01
  • Thanks Avt! I have hidden the status bar in my keyWindow, but when I added this code, the new window shows a status bar. I want to remove this status bar (hide it). I replaced the windowLevel like you mention, but it is still displaying the status bar :/ – KingPolygon Apr 18 '14 at 09:05
  • Sorry can not understand you. Also I need to see your code to help you. I suggest to open another ticket for your new issue. – Avt Apr 18 '14 at 09:09
  • I want to hide the status bar in notificationWindow. How would I do that? Thanks! – KingPolygon Apr 18 '14 at 09:12
  • I've asked the new question here! http://stackoverflow.com/questions/23151191/programatically-hiding-status-bar-when-adding-new-uiwindow – KingPolygon Apr 18 '14 at 09:23