我遇到了一个问题,我定义了一个UIScreenEdgePanGestureRecognizer来检测设备右边缘出现的平移手势,但该手势偶尔会被识别:
我有以下代码:
_swipeInLeftGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeInFromRightEdge:)];
_swipeInLeftGestureRecognizer.minimumNumberOfTouches = 1;
_swipeInLeftGestureRecognizer.maximumNumberOfTouches = 1;
[_swipeInLeftGestureRecognizer setEdges:UIRectEdgeRight];
[self.view addGestureRecognizer:_swipeInLeftGestureRecognizer];
- (void)handleSwipeInFromRightEdge:(UIGestureRecognizer*)sender
{
NSLog(@"swipe from right edge!!!!");
}
该手势附加到一个没有任何内容的视图。
我是不是错过了什么?
我已经设法创建了一个解决方法。这很简单。我已经将UIWindow划分为子类,并使用了touchesBegan/touchesMoved/等。模拟手势识别的方法。
它有效。UIWindow不会自动旋转,所以我必须相应地转换触摸坐标。
这是我的转换版本:
- (CGPoint)transformPoint:(CGPoint)point {
CGPoint pointInView = point;
if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
pointInView.x = self.bounds.size.width - pointInView.x;
pointInView.y = self.bounds.size.height - pointInView.y;
} else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) {
CGFloat x = pointInView.x;
CGFloat y = pointInView.y;
pointInView = CGPointMake(self.bounds.size.height - y, x);
} else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) {
CGFloat x = pointInView.x;
CGFloat y = pointInView.y;
pointInView = CGPointMake(y, self.bounds.size.width - x);
}
return pointInView;
}
我认为存在错误。我的应用程序总是处于横向模式,我和你设置了同样的东西,它检测右边缘。如果这个边缘是iPad的摄像头一侧,它会偶尔检测到。如果我把iPad翻过来,右边缘是按钮一侧,它就可以正常工作。事实上,我对任何手势都有这个问题,不仅仅是这个。