ios 滑动swipe识别

- (void)viewDidLoad {
    [super viewDidLoad];
 
 self.view.backgroundColor=[UIColor clearColor];
 
 UISwipeGestureRecognizer *recognizer;       
 recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromRight:)]; 
 [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];  
 [[self view] addGestureRecognizer:recognizer];     
 
 recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromLeft:)];   
 [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];   
 [[self view] addGestureRecognizer:recognizer];       
 
 recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromUp:)];  
 [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];  
 [[self view] addGestureRecognizer:recognizer];     
 
 recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromDown:)];  
 [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];    
 [[self view] addGestureRecognizer:recognizer];  
 
}

-(void)handleSwipeFromRight:(id)sender{  
 NSLog(@"Hello swipt right");
}
-(void)handleSwipeFromLeft:(id)sender{  
 NSLog(@"Hello swipt left");
}
-(void)handleSwipeFromDown:(id)sender{ 
 NSLog(@"Hello swipt down");
}
-(void)handleSwipeFromUp:(id)sender{   
 NSLog(@"Hello swipt up");
}

你可能感兴趣的:(ios,UP,action)