Thanks, alyanm. This is the closest solution I've found so far and it works as described.
BUT - I also need to let the UIWebView still detect and process clicks on links within the web form. I've tried a few crazy things (passing touches directly to webView, to webView.subviews[1], super first, super last) but no gain.
Has anyone solved for passing the up/down slide AND the clicks?
-- Update - PROBLEM SOLVED:
To pass the clicks, do this:
1) add a property to your (delegate) WebViewController as follows:
UIView *privateWebDocView; // plus @property, plus @synthesize
2) Add the following to your delegate method
- (void)webViewDidFinishLoad: (UIWebView *)webViewRef
{
CGPoint point = CGPointMake(100.0, 100.0);
self.privateWebDocView = [webViewRef hitTest: point withEvent:nil];
}
3) add the following to alyanm's wonderfully provided touchesEnded and touchesBegan methods, just above [super touches...]
if (self.privateWebDocView != nil)
[self.privateWebDocView touchesEnded:touches withEvent:event];
NOTE:
hitTest/privateWebDocView will get the (private) WebDoc embedded in the UIWebView so you can send hits to it, as explained in this other nifty post (page 2):
http://groups.google.com/group/iphon...82cd18d3c64168
Thanks for the posts in this thread which put me 90% there. I hope this update helps others.
- Bristo
P.P.S
- and thanks to youngcoder for the quick reply, too. Haven't read it yet; just saw it now, after typing he update into a stale browser window.
Quote:
Originally Posted by alyanm
I'm wondering if anybody ever did figure this out? How to implement swipes on top of a UIWebView while maintaining the vertical scroll capability? That's what I'm trying to do now, I can get the swipes to work by putting the transparent UIView on top -- but I don't know how to get the scrolll to work yet!
Update: Well, since nobody else seems to have figured this out, I did it myself. What I did is to pass the touch events on through the the webview UIScroller for vertical movements -- for horizontal movements I hold onto the events and use them for swipe detection. Works like a charm!
Here's some code using some stuff I stole from somebody else. wv is my UIWebView object:
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];
}
|