将粒子视图移动到屏幕前方?

时间:2014-04-18 07:55:32

标签: ios objective-c uiview uialertview caemitterlayer

我目前有一个连接到故事板的粒子视图。我面临的问题是,我在显示此视图的同时显示警报,并且警报始终显示在粒子视图的前面。有没有办法让我始终可以将粒子视图放在前面?我正在使用名为SIAlertView的第三方警报库,所以我假设它可能。

我已经记录了alertView的zPosition,它始终为0,所以我将粒子视图图层的zPosition设置为10,但它仍显示在警报视图下方。

这是故事板层次结构:

enter image description here

1 个答案:

答案 0 :(得分:1)

我不了解SIAlertView,但通过单独的窗口显示正常的UIAlertView。如果你想重叠它,你不能通过改变zpozition来做到这一点,你还必须使用一个单独的窗口:

// 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!

更新:

要重叠状态栏,请使用

notificationWindow.windowLevel = UIWindowLevelStatusBar;

取消UIWindow只是使指向它的强指针无效。类似的东西:

self.strongPointerToYourWindow = nil;
相关问题