菜单 - iOS开发:如何添加手势只有从最左边滑有效?
PHP中文网
PHP中文网 2017-04-17 17:37:41
0
2
720

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

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
大家讲道理

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;
        }
        
    }
}
    
    
Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template