unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow

≡放荡痞女 提交于 2019-11-29 01:51:50

I think it's a bug in iOS, which I can confirm on an iPad mini 2 and an iPad Air on iOS 7 or higher, even on the Home Screen.

In "Landscape Left" (Home button on the left) a "Right Edge Gesture" from outside the Screen is not working for me. Test it by your self on the Home Screen.

I reported a bug to Apple 9 Month ago, but noting further happened.

Update:

I played a bit with the UIWindow init and when it is a bit bigger than it really is, the Gesture works. Of course this is a horrible fix.

self.window = [UIWindow new];
self.window.rootViewController = [[UIViewController alloc] init];

// Real Size
CGRect frame = [UIScreen mainScreen].bounds;

// Real Size + 0.000001
self.window.frame = CGRectMake(0, 0, frame.size.width+0.000001, frame.size.height+0.000001);
[self.window makeKeyAndVisible];

I got the same issue. My solution works fine: just set in your xib your Windows to hidden.

I don't really understand why it works, but it works.

EDIT 1:

I found another solution, better I think, and more understandable:

Put this code on your willFinishLaunchingWithOptions, in your appDelegate:

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    CGRect bounds = [[UIScreen mainScreen] bounds];
    [self.window setFrame:bounds];
    [self.window setBounds:bounds];

    return YES;
}

Then, on your didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Your codes...

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

Your can then set your window object hidden to NO, and it should works.

I got issue when testing iPhone app on iPad. No problems on simulator and no problem if I compile app as universal and run on iPad.

unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UIClassicWindow: 0x1276065a0; frame = (0 0; 768 1024); userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x1740557e0>; layer = <UIWindowLayer: 0x17403fd80>>

Perhaps frame is reported wrong ? ( frame = (0 0; 768 1024) )

iOS 8 has a bug where any touch that begins exactly on an iPad right edge when in Portrait Upside-Down (home button on top) or Landscape Left (home button on left) mode fails to be hit tested to the correct view.

The fix is to subclass UIWindow to hit test the right side properly.

@implementation FixedWindow

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
  UIView* hit = [super hitTest:point withEvent:event];
  if (!hit && point.x >= CGRectGetMaxX(self.bounds))
    hit = [super hitTest:CGPointMake(point.x - 0.5, point.y) withEvent:event];
  return hit;
}

@end

Attach the window to your application delegate via the window property.

@implementation AppDelegate

- (UIWindow*)window
{
  if (!_window)
    _window = [[IVWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  return _window;
}

@end

In Portrait and Landscape Right modes, I've confirmed that right edge touches are always at least 0.5px from the edge instead of exactly on the edge, so this fix should work in analogy to that.

Expanding the window frame

Note that firebug's fix will also work i.e. slightly expanding the window frame to include the right side. However:

  • If you do this at application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions:, your view hierarchy doesn't get resized to the new frame and right edge touches won't make it through the hierarchy.
  • If you rotate the device, the window may not be centered correctly. This leads to either smearing or bumping interface elements slightly.

iOS 7:

iOS 7 has a similar bug in that the hit test also fails but with a non-nil result and unrotated geometry. This fix should work with both iOS 7 and 8:

@implementation FixedWindow

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
  UIView* hit = [super hitTest:point withEvent:event];
  if (!hit || hit == self)
  {
    CGRect bounds = self.bounds;
    hit = [super hitTest:CGPointMake(MIN(MAX(point.x, CGRectGetMinX(bounds) + 0.5), CGRectGetMaxX(bounds) - 0.5),
                                     MIN(MAX(point.y, CGRectGetMinY(bounds) + 0.5), CGRectGetMaxY(bounds) - 0.5))
               withEvent:event];
  }
  return hit;
}

@end

One possible fix is to remove or comment out code for hiding status bar if you have that. I was pulling my hair to solve it, and I could only reproduce it on my root view. It appears that if you hide the status bar you cannot drag down today widgets/notification center (you can with some effort).

/* <- add this
- (BOOL)prefersStatusBarHidden
{
   return YES;
}
add this -> */

Set your deployment to 8.x or above, set launch screen as your main xib.

Done!

It may be to late but some people may still need it, normally the cause is that you haven't supplied correctly sized launch images or a launch screen and/or Main Interface is not set to your own storyboard at General> Deployment Info

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!