Return to Snippet

Revision: 22329
at January 9, 2010 08:26 by iswear_wxp


Initial Code
#define HORIZ_SWIPE_DRAG_MIN 100
CGPoint 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];
	[[self.wv.subviews objectAtIndex:0] 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 zero
	double diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zero
	
	if(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 swipe
			return;
		}
		
		if (mystartTouchPosition.x < currentTouchPosition.x) {
			isProcessingListMove = YES;
			[self moveToPreviousItem];
			return;
		}
		else {
			isProcessingListMove = YES;
			[self moveToNextItem];
			return;
		}
	}
	else if(abs(diffy / diffx) > 1)
	{
		isProcessingListMove = YES;
		[[self.wv.subviews objectAtIndex:0] touchesMoved:touches	withEvent:event];	
		[super touchesMoved:touches	withEvent:event];
	}

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
	isProcessingListMove = NO;
	[super touchesEnded:touches withEvent:event];
	[[self.wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event];
}

Initial URL
http://www.iphonedevsdk.com/forum/iphone-sdk-development/2168-how-did-they-do-ereader-swipe-hidden-bottom-nav-uiwebview.html

Initial Description
wv is my UIWebView object

Initial Title
eReader swipe and hidden bottom nav in UIWebView

Initial Tags


Initial Language
iPhone