我试图在iPad上的iOS 8中设置边缘滑动手势但是获取和错误似乎是一个错误.
我有以下代码:
UIScreenEdgePanGestureRecognizer *edgeRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightEdgeSwipe:)]; edgeRecognizer.edges = UIRectEdgeRight; [self.view addGestureRecognizer:edgeRecognizer];
然后我处理手势:
-(void)handleRightEdgeSwipe:(UIGestureRecognizer*)sender { //slide in view code here }
问题是它不会每次都检测到右边缘滑动.有时它会多次检测到它.
无论是否检测到它在iPad上滑动右边缘时始终在控制台中显示以下信息:
2014-10-07 00:04:40.386 Office日志[1531:500896] _UIApplicationHandleEventFromQueueEvent中的意外nil窗口,_ windowowServerHitTestWindow :; layer =>
此消息的含义是什么?如何修复它以便始终检测到右边缘滑动?
我认为这是iOS中的一个错误,我可以在iOS 7或更高版本的iPad mini 2和iPad Air上进行确认,即使在主屏幕上也是如此.
在"左侧风景"(左侧的主页按钮)中,屏幕外部的"右边缘手势"对我不起作用.在主屏幕上由您自己测试.
我在9个月前向Apple报告了一个错误,但注意到了进一步的发生.
我在UIWindow初始化时玩了一下,当它比实际大一点时,Gesture工作.当然这是一个可怕的修复.
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];
我在iPad上测试iPhone应用程序时遇到了问题.如果我将应用程序编译为通用并在iPad上运行,那么在模拟器上没有问题并且没有问题.
unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UIClassicWindow: 0x1276065a0; frame = (0 0; 768 1024); userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x1740557e0>; layer = <UIWindowLayer: 0x17403fd80>>
也许帧报错了?(frame =(0 0; 768 1024))
我遇到了同样的问题.我的解决方案工作正常:只需在你的xib中设置你的Windows隐藏.
我真的不明白为什么它有效,但它确实有效.
编辑1:
我找到了另一个解决方案,我认为更好,也更容易理解:
将此代码放在appDelegate中的willFinishLaunchingWithOptions上:
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CGRect bounds = [[UIScreen mainScreen] bounds]; [self.window setFrame:bounds]; [self.window setBounds:bounds]; return YES; }
然后,在你的didFinishLaunchingWithOptions上:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Your codes... self.window.rootViewController = self.navigationController; [self.window makeKeyAndVisible]; return YES; }
然后你可以将你的窗口对象隐藏为NO,它应该可以工作.