/**
- 添加平移手勢(shì)
- @param view
*/
-
(void)addTapGestureWithView:(UIView *)view
{UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipe:)];
[self.view addGestureRecognizer:recognizer];
[recognizer release];
}
/**
- 平移手勢(shì)響應(yīng)事件
- @param swipe swipe description
*/
-
(void)handleSwipe:(UIPanGestureRecognizer *)swipe
{if (swipe.state == UIGestureRecognizerStateChanged) {
[self commitTranslation:[swipe translationInView:self.view]];
}
}
/**
- 判斷手勢(shì)方向
- @param translation translation description
*/
-
(void)commitTranslation:(CGPoint)translation
{CGFloat absX = fabs(translation.x);
CGFloat absY = fabs(translation.y);// 設(shè)置滑動(dòng)有效距離
if (MAX(absX, absY) < 10)
return;
if (absX > absY ) {
if (translation.x<0) {
//向左滑動(dòng)
}else{
//向右滑動(dòng)
}
} else if (absY > absX) {
if (translation.y<0) {
//向上滑動(dòng)
}else{
//向下滑動(dòng)
}
}
}