ios - UIScreenEdgePanGestureRecognizer 不能检测到状态?
迷茫
迷茫 2017-04-17 17:56:26
0
1
272

我有一个侧滑菜单,使用UIScreenEdgePanGestureRecognizer来从屏幕边缘,由左至右滑动打开,由右至左滑动关闭。

现在的问题是,我从右至左快速滑动时(或者使用真机调试,手指从右向左,手机重新触碰屏幕边缘时),侧滑菜单就会停留在半打开的状态,这个时候检测不到if(sender.state == UIGestureRecognizerStateEnded).

我的代码如下:

self.panGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureDo:)]; -(void)panGestureDo:(UIScreenEdgePanGestureRecognizer *)sender{ // NSLog(@"%ld",(long)sender.state); if(sender.state == UIGestureRecognizerStateBegan){ self.startLocation = [sender locationInView:self.view]; } self.currentLocation = [sender locationInView:self.view]; CGFloat distance = self.startLocation.x - self.currentLocation.x; if(distance < 0){ [self.mainView addSubview:self.blurEffectView]; [self.blurEffectView addGestureRecognizer:self.tapGesture]; self.blurEffectView.alpha = (-distance)/100; self.leftMenu.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.leftMenuWidth, self.view.frame.size.height); self.mainView.frame =CGRectMake(self.view.frame.origin.x - distance, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height); if (self.mainView.frame.origin.x > 97) { self.mainView.frame =CGRectMake(self.view.frame.origin.x + self.leftMenuWidth, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height); [self openMenuHalfAnimation]; } if (self.mainView.frame.origin.x < 3) { self.mainView.frame =CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height); [self closeMenuHalfAnimation]; } if(sender.state == UIGestureRecognizerStateEnded){ //当手势结束时,判断侧滑菜单的位置,自动打开或者关闭。 //但是当从右向左滑动速度过快,就不会进入这个if条件里面。 NSLog(@"UIGestureRecognizerStateEnded"); if (self.mainView.frame.origin.x > 50) { [self openMenuHalfAnimation]; }else{ [self closeMenuHalfAnimation]; } } //下面的我都试过,检测不到滑动过快的情况。 if(sender.state == UIGestureRecognizerStateCancelled){ NSLog(@"UIGestureRecognizerStateCancelled"); } if(sender.state == UIGestureRecognizerStateFailed){ NSLog(@"UIGestureRecognizerStateFailed"); } if(sender.state == UIGestureRecognizerStatePossible){ NSLog(@"UIGestureRecognizerStatePossible"); } // if(sender.state == UIGestureRecognizerStateChanged){ // NSLog(@"UIGestureRecognizerStateChanged"); // } if(sender.state == UIGestureRecognizerStateBegan){ NSLog(@"UIGestureRecognizerStateBegan"); } if(sender.state == UIGestureRecognizerStateRecognized){ NSLog(@"UIGestureRecognizerStateRecognized"); } } }

我还尝试过这些,但是都没有被调用。

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touches end"); } -(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"touches canceled"); }
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全員に返信 (1)
巴扎黑

楼主 解决了吗

いいねを押す+0
    最新のダウンロード
    詳細>
    ウェブエフェクト
    公式サイト
    サイト素材
    フロントエンドテンプレート
    私たちについて 免責事項 Sitemap
    PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!