• iOS开发-UISwipeGestureRecognizer滑动手势


    滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧:

        UISwipeGestureRecognizer  *upSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
        upSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionUp;
        [self.view addGestureRecognizer:upSwipeGestureRecognizer];
        
        
        UISwipeGestureRecognizer  *downSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
        downSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionDown;
        [self.view addGestureRecognizer:downSwipeGestureRecognizer];
        
        
        UISwipeGestureRecognizer  *leftSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
        leftSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:leftSwipeGestureRecognizer];
        
        
        UISwipeGestureRecognizer  *rightSwipeGestureRecognizer=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureRecognizer:)];
        rightSwipeGestureRecognizer.direction=UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:rightSwipeGestureRecognizer];
    

    手势处理:

    -(void)swipeGestureRecognizer:(UISwipeGestureRecognizer *)recongnizer{
        if (recongnizer.direction==UISwipeGestureRecognizerDirectionUp) {
            NSLog(@"向上滑动");
            NSLog(@"博客园-FlyElephant");
        }
        
        if (recongnizer.direction==UISwipeGestureRecognizerDirectionDown) {
            NSLog(@"向下滑动");
            NSLog(@"原文地址:http://www.cnblogs.com/xiaofeixiang");
        }
        
        if (recongnizer.direction==UISwipeGestureRecognizerDirectionLeft) {
            NSLog(@"向左滑动");
            NSLog(@"iOS技术交流群:228407086");
        }
        
        if (recongnizer.direction==UISwipeGestureRecognizerDirectionRight) {
            NSLog(@"向右滑动");
        }
    }
    

    效果图:

  • 相关阅读:
    主机无法ping通网关,但可以ping通局域网内的其他主机
    linux下安装mysql
    国内python源
    在vue中引入element-ui时报错
    在windows上部署vue
    linux上部署vue开发环境
    vue插件之vue-router路由基本使用
    vue监听属性变化
    vue过滤器
    vue组件的使用
  • 原文地址:https://www.cnblogs.com/xiaofeixiang/p/4586316.html
Copyright © 2020-2023  润新知