iOS-自定义手势操作

Posted 极客学伟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS-自定义手势操作相关的知识,希望对你有一定的参考价值。

1.自定义全局手势操作

@property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //原生方法无效
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    //设置手势
    self.panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(openMenuClick)];
    [self.view addGestureRecognizer:self.panGestureRecognizer];

}

-(void)openMenuClick{
    //进行相应操作
    NSLog(@"进行相应操作");
}

2.局部手势

/** 左滑手势 */
@property (nonatomic, strong) UIScreenEdgePanGestureRecognizer *edgePanGestureRecognizer;

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //原生方法无效
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    self.edgePanGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(openMenuClick)];
    self.edgePanGestureRecognizer.delegate = self;
    self.edgePanGestureRecognizer.edges = UIRectEdgeRight;
    [self.view addGestureRecognizer:self.edgePanGestureRecognizer];
}

-(void)openMenuClick{
    //进行相应操作
    NSLog(@"进行相应操作");
}

以上是关于iOS-自定义手势操作的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——git命令操作一个完整流程

ios10自定手势有啥用

转iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) -- 不错不错

iOS手势(滑动)返回的实现(自定义返回按钮)

Runtime__iOS利用Runtime自定义控制器POP手势动画

iOS自定义全屏返回与tableView左划删除手势冲突解决