/ Published in: iPhone
wv is my UIWebView object
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#define HORIZ_SWIPE_DRAG_MIN 100 CGPoint mystartTouchPosition; BOOL isProcessingListMove; { 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]; [[self.wv.subviews objectAtIndex:0] touchesBegan:touches withEvent: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 zero double diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zero { // It appears to be a swipe. if(isProcessingListMove) { // ignore move, we're currently processing the swipe return; } if (mystartTouchPosition.x < currentTouchPosition.x) { isProcessingListMove = YES; [self moveToPreviousItem]; return; } else { isProcessingListMove = YES; [self moveToNextItem]; return; } } { isProcessingListMove = YES; [[self.wv.subviews objectAtIndex:0] touchesMoved:touches withEvent:event]; [super touchesMoved:touches withEvent:event]; } } { isProcessingListMove = NO; [super touchesEnded:touches withEvent:event]; [[self.wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event]; }