1

I'm creating a jailbreak tweak that adds a view to the UIWindow of whatever the current keyWindow is. The problem is that whenever the keyWindow changes the view gets removed.

I'm using this

%hook SBApplication
-(void)willActivate {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,320,53)];
    view.backgroundColor = [UIColor greenColor];
    [window addSubview:view];
}
%end

is there another method that is better to use here or is there a notification that is sent whenever the window changes?

4

2 回答 2

2

是的,您可以观察到一个通知:

UIWindowDidBecomeKey

每当 UIWindow 对象成为关键窗口时发布。通知对象是成为关键的窗口对象。此通知不包含 userInfo 字典。

更多在文档中。

于 2018-04-04T00:02:49.990 回答
1

弄清楚了!

更改 keyWindow 时调用的方法在 UIWindow 中,方法是

-(void)makeKeyWindow

只需挂钩,然后添加您的子视图!

于 2014-11-19T02:02:48.670 回答