zoukankan      html  css  js  c++  java
  • UISwipeGestureRecognizer 左右事件捕捉

    转自:http://blog.163.com/china_uv/blog/static/117137267201252102612185/

    UISwipeGestureRecognizer 左右事件相同为非注释代码, 左右事件不同为注释代码。

    @implementation GestureRecognizerViewController

    -(id)init
    {
        if (self == [super init]) {
            
            UISwipeGestureRecognizer *recognizer;    
            recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
            [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight];
            [[self view] addGestureRecognizer:recognizer];    
            [recognizer release];
            
    //        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
    //        [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
    //        [[self view] addGestureRecognizer:recognizer];    
    //        [recognizer release];
    //        
    //        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];    
    //        [recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
    //        [[self view] addGestureRecognizer:recognizer];    
    //        [recognizer release];
            
        }
        
        return self;
    }

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        self.view.backgroundColor = [UIColor darkGrayColor];
    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }


    -(void) dealloc
    {
        for (UISwipeGestureRecognizer *recognizer in [[self view] gestureRecognizers]) {  
            [[self view] removeGestureRecognizer:recognizer];  
        } 
        
        [super dealloc];
    }

    // ------------------------------------------------------------------------

    - (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{    
        
        NSLog(@"direction ------------- %d", recognizer.direction);
        
        
        if (recognizer.direction == (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)) {    
            NSLog(@"left & right");  
        }
        
    //    if (UISwipeGestureRecognizerDirectionLeft == recognizer.direction) {    
    //        NSLog(@"left");  
    //    }
    //    
    //    if (UISwipeGestureRecognizerDirectionRight == recognizer.direction) {    
    //        NSLog(@"right");  
    //    }
    }


    感叹下IOS的智慧,UISwipeGestureRecognizerDirection定义用的是位移。
    typedef enum {
        UISwipeGestureRecognizerDirectionRight = 1 << 0,
        UISwipeGestureRecognizerDirectionLeft  = 1 << 1,
        UISwipeGestureRecognizerDirectionUp    = 1 << 2,
        UISwipeGestureRecognizerDirectionDown  = 1 << 3
    } UISwipeGestureRecognizerDirection;

  • 相关阅读:
    Django——缓存
    Django——中间件设置缓存
    Django——photo
    Django——权限
    ONVIF Event消息解析(How to work with gSoap)
    当OOP语言RAII特性发展到functional形式的极致
    探讨符号式未来,函数式语言//冒号说明法
    JavaScript 目标装配式编程(Target Assemble Programming)
    When Colon Scripting is comming(JavaScript语法扩充)
    When Colon Scripting is comming (脚本最佳体验)
  • 原文地址:https://www.cnblogs.com/wangpei/p/4260046.html
Copyright © 2011-2022 走看看