拖动图片方向的判断

/**
*拖动手势
*/
- (void)panGestureAction:(UIPanGestureRecognizer*)recognizer {
//if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPointtranslation = [recognizertranslationInView:recognizer.view];
CGPointnewCenter =CGPointMake(recognizer.view.center.x+ translation.x, recognizer.view.center.y+ translation.y);
CGRectviewRect = [self.viewconvertRect:self.bigImageView.frametoView:nil];
CGFloatorigin_left_x = viewRect.origin.x;
CGFloatorigin_right_x = viewRect.size.width+ origin_left_x;
CGFloatorigin_top_y = viewRect.origin.y;
CGFloatorigin_bottom_y = viewRect.size.height+ origin_top_y;
CGPointvelocity = [recognizervelocityInView:self.view];
if(translation.y==0||fabs(translation.x/ translation.y) >5) {
if(velocity.x>0) {//向右滑动
if(origin_left_x >=0) {
return;
}
}else{//向左滑动
if(origin_right_x <=mScreenWidth) {
return;
}
}
recognizer.view.center= newCenter;
【拖动图片方向的判断】[recognizersetTranslation:CGPointZeroinView:self.view];
}
if(translation.x==0||fabs(translation.y/ translation.x) >5) {
if(velocity.y>0) {//向下滑动
if(origin_top_y >=0) {
return;
}
}else{//向上滑动
if(origin_bottom_y <=mScreenHeight) {
return;
}
}
recognizer.view.center= newCenter;
[recognizersetTranslation:CGPointZeroinView:self.view];
}
//}
}

    推荐阅读