ios開発でタッチスクリーン操作の画面で上下または左右にスライドさせるサンプルコード

サンプルコード
infoView=[[UIView alloc] initWithFrame:CGRectMake(25, 110,210, 270)];
infoView.backgroundColor=[UIColor blueColor];
infoView.alpha=0.6;
[self.view addSubview:infoView];
/******************ジェスチャー監視*****************/
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[infoView addGestureRecognizer:recognizer];
// recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
// [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
// [self.view addGestureRecognizer:recognizer];
// recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
// [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
// [self.view addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[infoView addGestureRecognizer:recognizer];
//タッチイベント機能の実現
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@”****************左スライド****************”);
}
if(recognizer.direction==UISwipeGestureRecognizerDirectionRight) {
NSLog(@”****************右スライド****************”);
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionDown){
NSLog(@”****************下スライド****************”);
}
if (recognizer.direction==UISwipeGestureRecognizerDirectionUp){
NSLog(@”****************上スライド****************”);
}
}

Comments are closed.