search

Home  >  Q&A  >  body text

菜单 - iOS开发:如何添加手势只有从最左边滑有效?

公司APP类似Uber,从最左侧滑动会出现菜单,但需要用到地图,添加全屏的tap手势会产生冲突,求大神支招,如何结局啊?急急急

PHP中文网PHP中文网2810 days ago753

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:39:41

    Do you want it to only work if you swipe right from the left edge of the screen? If so, adding an edge gesture will do the trick! As follows:

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIScreenEdgePanGestureRecognizer* screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(action:)];
        screenEdgePan.edges = UIRectEdgeLeft;
        [self.view addGestureRecognizer:screenEdgePan];
     
    }
        
    -(void)action:(UIScreenEdgePanGestureRecognizer*)sender{
        if (sender.edges == UIRectEdgeLeft) {
            NSLog(@"正在从左边滑动");
            switch (sender.state) {
                case UIGestureRecognizerStateBegan:
                    NSLog(@"手势开始");
                    break;
                case UIGestureRecognizerStateChanged:
                    NSLog(@"手势进行中");
                    break;
                case UIGestureRecognizerStateEnded:
                    NSLog(@"手势结束");
                    break;
                    
                default:
                    break;
            }
            
        }
    }
        
        

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:39:41

    I don’t know ios, but in Android it can be limited by judging the x coordinate position of the first point. This is just an idea, I haven’t tried it. I wonder if there is a similar idea for ios

    reply
    0
  • Cancelreply