unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow

佐手、 提交于 2019-11-27 16:14:44

问题


I am trying to set up an edge swipe gesture in iOS 8 on iPad but getting and error that seems like a bug.

I have the following code:

    UIScreenEdgePanGestureRecognizer *edgeRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightEdgeSwipe:)];
edgeRecognizer.edges = UIRectEdgeRight;
[self.view addGestureRecognizer:edgeRecognizer];

and then I handle the gesture:

-(void)handleRightEdgeSwipe:(UIGestureRecognizer*)sender
{
//slide in view code here
}

The problem is that it doesn't detect the right edge swipe every time. And sometimes it detects it multiple times.

Whether it detects or not it always shows the following information in the console when swiping the right edge on iPad:

2014-10-07 00:04:40.386 Office Log[1531:500896] unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: ; layer = >

What does this message mean and how can I fix it so that the right edge swipe is detected consistently?


回答1:


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];



回答2:


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.




回答3:


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) )




回答4:


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



回答5:


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



回答6:


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

Done!




回答7:


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



来源:https://stackoverflow.com/questions/26226259/unexpected-nil-window-in-uiapplicationhandleeventfromqueueevent-windowserverh

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