你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS 上下左右手勢識別

iOS 上下左右手勢識別

編輯:IOS開發綜合
- (void)viewDidLoad {   //建立滑動手勢     UISwipeGestureRecognizer *recognizer;        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];    //設置滑動方向,下面以此類推     [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];        [[self view] addGestureRecognizer:recognizer];        [recognizer release];          recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];        [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];        [[self view] addGestureRecognizer:recognizer];        [recognizer release];               recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];        [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];       [[self view] addGestureRecognizer:recognizer];        [recognizer release];               recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom:)];        [recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];        [[self view] addGestureRecognizer:recognizer];        [recognizer release];          [super viewDidLoad];    }      //這個是協議回調,所以需要遵循 UIGestureRecognizerDelegate協議 -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {         NSLog(@"Swipe received.");    www.2cto.com      if (recognizer.direction==UISwipeGestureRecognizerDirectionDown) {                    NSLog(@"向下滑動");       //執行程序        }        if (recognizer.direction==UISwipeGestureRecognizerDirectionUp) {         NSLog(@"向上滑動");       //執行程序        }        if (recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {         NSLog(@"向左滑動");       //執行程序        }        if (recognizer.direction==UISwipeGestureRecognizerDirectionRight) {         NSLog(@"向右滑動");       //執行程序        }   }  
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved