eReader swipe and hidden bottom nav in UIWebView


/ Published in: iPhone
Save to your folder(s)

wv is my UIWebView object


Copy this code and paste it in your HTML
  1. #define HORIZ_SWIPE_DRAG_MIN 100
  2. CGPoint mystartTouchPosition;
  3. BOOL isProcessingListMove;
  4.  
  5. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  6. {
  7. UITouch *touch = [touches anyObject];
  8. CGPoint newTouchPosition = [touch locationInView:self.view];
  9. if(mystartTouchPosition.x != newTouchPosition.x || mystartTouchPosition.y != newTouchPosition.y) {
  10. isProcessingListMove = NO;
  11. }
  12. mystartTouchPosition = [touch locationInView:self.view];
  13. [super touchesBegan:touches withEvent:event];
  14. [[self.wv.subviews objectAtIndex:0] touchesBegan:touches withEvent:event];
  15. }
  16.  
  17. -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  18. {
  19. UITouch *touch = touches.anyObject;
  20. CGPoint currentTouchPosition = [touch locationInView:self.view];
  21.  
  22. // If the swipe tracks correctly.
  23. double diffx = mystartTouchPosition.x - currentTouchPosition.x + 0.1; // adding 0.1 to avoid division by zero
  24. double diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zero
  25.  
  26. if(abs(diffx / diffy) > 1 && abs(diffx) > HORIZ_SWIPE_DRAG_MIN)
  27. {
  28. // It appears to be a swipe.
  29. if(isProcessingListMove) {
  30. // ignore move, we're currently processing the swipe
  31. return;
  32. }
  33.  
  34. if (mystartTouchPosition.x < currentTouchPosition.x) {
  35. isProcessingListMove = YES;
  36. [self moveToPreviousItem];
  37. return;
  38. }
  39. else {
  40. isProcessingListMove = YES;
  41. [self moveToNextItem];
  42. return;
  43. }
  44. }
  45. else if(abs(diffy / diffx) > 1)
  46. {
  47. isProcessingListMove = YES;
  48. [[self.wv.subviews objectAtIndex:0] touchesMoved:touches withEvent:event];
  49. [super touchesMoved:touches withEvent:event];
  50. }
  51.  
  52. }
  53.  
  54. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  55. {
  56. isProcessingListMove = NO;
  57. [super touchesEnded:touches withEvent:event];
  58. [[self.wv.subviews objectAtIndex:0] touchesEnded:touches withEvent:event];
  59. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.