1

I've been following this example in everything to create a UIWindow on top of the statusBar.

My UIWindow gets displayed on top of the statusBar and all is fine, but the actual view of the app (the one with the button) doesn't respond to my actions:

enter image description here

I'm using Storyboards and iOS6. Here's my code for creating a statusBar overlay:

- (void)viewDidAppear:(BOOL)animated     {

    UIWindow *overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
    AppDelegate *app = [[UIApplication sharedApplication] delegate];

    overlayWindow.rootViewController = app.window.rootViewController;
    app.window  = overlayWindow;
    [overlayWindow makeKeyAndVisible];

}

The view under the statusBar does not respond and I can't tap on the UIButton. Is it possible to somehow make the UIWindow with the interface of my app accept the touches ignoring the ACStatusBarOverlayWindow? How can that be done?

Community
  • 1
  • 1
Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120

1 Answers1

0

Usually if a button does not respond to a touch it's because the button is outside of the bounds of it's parent's UIView.

Your code does not seem to be the appropriate approach to the problem you're trying to solve. If you just need your window to have a status bar, or you just need to add a button to you current view, the way you're doing it is probably incorrect.

Personally I've never seen anyone instantiate a UIWindow in a viewDidAppear, since the app comes with it's own UIWindow. You should be using a UIView and adding your overlay to it.

As a side note if you were to do it the way you're attempting to, then your window would at least need a frame. So initWithFrame:CGRectZero would be initWithFrame:CGRectMake(0,0,320,480) or something along those lines.

A better way to approach the problem is to instantiate a UIViewController and set it as your rootViewController. Or simply add your button to the current viewController's view.

- (void)viewDidLoad     {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self 
               action:@selector(myMethod:)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"Tap Me" forState:UIControlStateNormal];
    [button sizeToFit];
    [self.view addSubview:button];
}
Matt Hudson
  • 7,329
  • 5
  • 49
  • 66
  • Yes, sir! I have the exact same code in my ViewDidLoad method! I think you misunderstood my question, I'm creating a UIWindow to be able to create a view on top of the status bar. And by the way, how do I instantiate my ViewController for it to be the rootViewController? – Sergey Grischyov Dec 26 '12 at 15:57
  • I'm sorry, I've figured it out already. Thanks for your help! – Sergey Grischyov Dec 26 '12 at 17:30