首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

判断上下拖动画面 iphone

2012-07-15 
判断左右拖动画面iphone#define HORIZ_SWIPE_DRAG_MIN 100CGPoint mystartTouchPositionBOOL isProcessin

判断左右拖动画面 iphone

#define HORIZ_SWIPE_DRAG_MIN 100CGPoint mystartTouchPosition;BOOL isProcessingListMove;- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch = [touches anyObject];CGPoint newTouchPosition = [touch locationInView:self.view];if(mystartTouchPosition.x != newTouchPosition.x || mystartTouchPosition.y != newTouchPosition.y) {isProcessingListMove = NO;}mystartTouchPosition = [touch locationInView:self.view];[super touchesBegan:touches withEvent:event];}-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {UITouch *touch = touches.anyObject;CGPoint currentTouchPosition = [touch locationInView:self.view];// If the swipe tracks correctly.double diffx = mystartTouchPosition.x - currentTouchPosition.x + 0.1; // adding 0.1 to avoid division by zerodouble diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zeroif(abs(diffx / diffy) > 1 && abs(diffx) > HORIZ_SWIPE_DRAG_MIN){// It appears to be a swipe.if(isProcessingListMove) {// ignore move, we're currently processing the swipereturn;}if (mystartTouchPosition.x < currentTouchPosition.x) {isProcessingListMove = YES;[self moveToPreviousItem];return;}else {isProcessingListMove = YES;[self moveToNextItem];return;}}else if(abs(diffy / diffx) > 1){isProcessingListMove = YES;[super touchesMoved:toucheswithEvent:event];}}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {isProcessingListMove = NO;[super touchesEnded:touches withEvent:event];}
-(void)moveToPreviousItem{NSLog(@"Move To Previous Item");}-(void)moveToNextItem{NSLog(@"Move To Next Item");}

? 这里的isProcessingListMove 是一个BOOL布尔类型,mystartTouchPosition是CGPoint类型,可以用的!

热点排行