zoukankan      html  css  js  c++  java
  • ios学习之UISwipeGestureRecognizer手势识别

    ios学习之UISwipeGestureRecognizer手势识别

     

     

    本文部分转自俺是一个瓜娃!!!的博客UISwipeGestureRecognizer ---手指动作,转载过来仅是为了自己查询方便。

     
     

    tap是指轻触手势。类似鼠标操作的点击。从iOS 3.2版本开始支持完善的手势api:

     

    • tap:轻触
    • long press:在一点上长按
    • pinch:两个指头捏或者放的操作
    • pan:手指的拖动
    • swipe:手指在屏幕上很快的滑动
    • rotation:手指反向操作

     

    - (void)viewDidLoad

     

    {

     [superviewDidLoad];

        infoView=[[UIViewalloc] initWithFrame:CGRectMake(20300768-40070)]; 

        infoView.backgroundColor=[UIColorblueColor]; 

        infoView.alpha=0.6; 

        infoView.layer.cornerRadius=6

        infoView.layer.masksToBounds=YES

        [self.view addSubview:infoView]; 

       /******************监视手势控制*****************/

        UISwipeGestureRecognizer *recognizer; 

        

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 

        [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)]; 

        [[selfview] addGestureRecognizer:recognizer]; 

        [recognizer release]; 

        

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 

        [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)]; 

        [[selfview] addGestureRecognizer:recognizer]; 

        [recognizer release]; 

        

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 

        [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)]; 

        [[selfview] addGestureRecognizer:recognizer]; 

        [recognizer release]; 

        

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 

        [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 

        [[selfview] addGestureRecognizer:recognizer]; 

        [recognizer release]; 

    }

     

    /******************手势控制操作及切换特效*****************/

    //滑动事件1

    -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{

        //如果往左滑

        if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {

            //先加载数据,再加载动画特效

            [self nextQuestion];

            self.view.frame = CGRectMake(320, 0, 320, 480);

            [UIViewbeginAnimations:@"animationID"context:nil];

            [UIViewsetAnimationDuration:0.3f];

            [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

            [UIViewsetAnimationRepeatAutoreverses:NO];

            self.view.frame = CGRectMake(0, 0, 320, 480);

            [UIViewcommitAnimations];

        }

        //如果往右滑

        if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {

            [self lastQuestion];

            self.view.frame = CGRectMake(-320, 0, 320, 480);

            [UIViewbeginAnimations:@"animationID"context:nil];

            [UIViewsetAnimationDuration:0.3f];

            [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

            [UIViewsetAnimationRepeatAutoreverses:NO];

            self.view.frame = CGRectMake(0, 0, 320, 480);

            [UIViewcommitAnimations];

        }

    }

    //滑动触发事件2

    -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 

        NSLog(@"Swipe received."); 

        

        if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) { 

            NSLog(@"swipe down");

     

            [UIViewbeginAnimations:@"animationID"context:nil]; 

            [UIViewsetAnimationDuration:0.7f]; 

            [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut]; 

            [UIViewsetAnimationRepeatAutoreverses:NO]; 

            [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.viewcache:YES];

            [infoViewremoveFromSuperview]; 

            [self.view addSubview:infoView];

            [UIViewcommitAnimations];

        }

        

        if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) { 

            NSLog(@"swipe up");

            

            [UIViewbeginAnimations:@"animationID"context:nil]; 

            [UIViewsetAnimationDuration:0.7f]; 

            [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut]; 

            [UIViewsetAnimationRepeatAutoreverses:NO]; 

            [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];

            [infoViewremoveFromSuperview]; 

            [self.view addSubview:infoView];

            [UIViewcommitAnimations];

        }

    }

    //点击出发事件

    -(void)handleTapFrom:(UITapGestureRecognizer *)recognizer{

        NSLog(@">>>tap it");

    }

  • 相关阅读:
    阿里巴巴的26款超神Java开源项目
    10个爬虫工程师必备的工具
    微服务的发现与注册--Eureka
    国内最火5款Java微服务开源项目
    LeetCode 700. 二叉搜索树中的搜索
    LeetCode 104. 二叉树的最大深度
    LeetCode 908. 最小差值 I
    LeetCode 728. 自除数
    LeetCode 704. 二分查找
    LeetCode 852. 山脉数组的峰顶索引 (二分)
  • 原文地址:https://www.cnblogs.com/haijieFeng/p/4103802.html
Copyright © 2011-2022 走看看