zoukankan      html  css  js  c++  java
  • iPhone 简单手势的判断

     

    不知道4.0SDK带有手势的直接支持没有,至少3.2已经可以用了.但是如果想支持早期的版本,那么手势的识别无疑是一种痛苦,因为需要自己写代码来判定手势...

     

    下面代码是判断一个滑动的手势(swipe),虽然很简单但是总体思想就是这样了.当在一个水平,或者纵向滑动时给出一个滑动距离以及偏移量.当实际滑动距离超过指定的距离,且水平或者纵向的偏移量小于指定的偏移量则视为这个滑动手势判定成功!

     

    Java代码 
    1. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event   
    2. {   
    3.     UITouch *touch = touches.anyObject;   
    4.     CGPoint currentTouchPosition = [touch locationInView:self];   
    5.       
    6.     if (fabsf(startTouchPosition.x - currentTouchPosition.x) >=   
    7.         HORIZ_SWIPE_DRAG_MIN &&   
    8.         fabsf(startTouchPosition.y - currentTouchPosition.y) <=   
    9.         VERT_SWIPE_DRAG_MAX)   
    10.     {   
    11.         // Horizontal Swipe  
    12.         if (startTouchPosition.x < currentTouchPosition.x) {  
    13.             NSLog(@"from left");  
    14.             dirString = kCATransitionFromLeft;  
    15.         }  
    16.         else   
    17.             NSLog(@"from right");  
    18.             dirString = kCATransitionFromRight;  
    19.     }   
    20.     else if (fabsf(startTouchPosition.y - currentTouchPosition.y) >=   
    21.              HORIZ_SWIPE_DRAG_MIN &&   
    22.              fabsf(startTouchPosition.x - currentTouchPosition.x) <=   
    23.              VERT_SWIPE_DRAG_MAX)  
    24.     {   
    25.         // Vertical Swipe  
    26.         if (startTouchPosition.y < currentTouchPosition.y)   
    27.             dirString = kCATransitionFromBottom;  
    28.         else   
    29.             dirString = kCATransitionFromTop;  
    30.     } else   
    31.     {  
    32.         // Process a non-swipe event.   
    33.         // dirString = NULL;  
    34.     }  
    35. }   
    36.   
    37. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event   
    38. {  
    39.     if (dirString)   
    40.     {  
    41.         // do it      
    42.     }  

    id 博主 = [[KILONET.CNBLOGS.COM alloc] initWithValue:@"天堂向右,我依然向左"

                  网名:@"老舟"

                  兴趣:@"影音,阅读"

                  动态:@"系统架构设计,Android通信模块开发"

                  网址:@"http://kilonet.cnblogs.com"
                  签名:@"--------------------------------------------------

                                  Stay Hungry , Stay Foolish

                                  求  知  若  渴,处  事  若  愚

                              --------------------------------------------------"

                  ];         // Never Release

  • 相关阅读:
    10. Regular Expression Matching
    9. Palindrome Number
    6. ZigZag Conversion
    5. Longest Palindromic Substring
    4. Median of Two Sorted Arrays
    3. Longest Substring Without Repeating Characters
    2. Add Two Numbers
    链式表的按序号查找
    可持久化线段树——区间更新hdu4348
    主席树——树链上第k大spoj COT
  • 原文地址:https://www.cnblogs.com/KiloNet/p/1807332.html
Copyright © 2011-2022 走看看