Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2008, 02:07 PM   #1 (permalink)
mdj
New Member
 
Join Date: Aug 2008
Posts: 5
mdj is on a distinguished road
Default How did they do it? eReader swipe and hidden bottom nav in UIWebView

We can't figure out how to register a swipe in UIWebView like they use for turning pages in eReader (free app in appstore).

Also, they hide the bottom nav on a tap and make it reappear with a tap, not sure how to do that though.

Any helpful pointers would be great. Thanks!
mdj is offline   Reply With Quote
Old 08-04-2008, 02:17 PM   #2 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

Try putting a UIView subclass over the UIWebView? Just override the swipe method so the rest of the touch events go to the UIWebView.

Max
mxweas is offline   Reply With Quote
Old 08-04-2008, 02:25 PM   #3 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

I have no idea what I was thinking... Just subclass UIWebView and override the swipe gesture method of UIView.

Max
mxweas is offline   Reply With Quote
Old 08-04-2008, 05:20 PM   #4 (permalink)
mdj
New Member
 
Join Date: Aug 2008
Posts: 5
mdj is on a distinguished road
Default Tried...

We tried this first suggestion, but because it is transparent it doesn't register. I'll try your other suggestion out. thanks

Quote:
Originally Posted by mxweas View Post
Try putting a UIView subclass over the UIWebView? Just override the swipe method so the rest of the touch events go to the UIWebView.

Max

Last edited by mdj; 08-04-2008 at 05:25 PM.
mdj is offline   Reply With Quote
Old 08-04-2008, 05:38 PM   #5 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

Transparency does not determine what receives events. Make sure the UIView that is subclass'd is being placed as a subview last, thus putting it on top of all other views.

Max

PS: Make sure you're not using CGRectZero or anything
mxweas is offline   Reply With Quote
Old 08-04-2008, 06:47 PM   #6 (permalink)
mdj
New Member
 
Join Date: Aug 2008
Posts: 5
mdj is on a distinguished road
Default

I created a UIView Subclass and put it on top of the UIWebView. I can detect double taps, but I'm not sure how to pass the touch event up the chain to the UIWebView if it doesn't match our tapCount. Here's the code I'm using. Any thoughts?

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *theTouch = [touches anyObject];
	
	if (theTouch.tapCount == 2) {
		NSLog(@"Double Tap");
	} else {
		// We want to pass the response up the chain to the UIWebView
		[self.superview touchesBegan:touches withEvent:event];
	}
}
mdj is offline   Reply With Quote
Old 08-04-2008, 08:03 PM   #7 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

Try subclassing UIWebView and doing this:

Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *theTouch = [touches anyObject];
	
	if (theTouch.tapCount == 2) {
		NSLog(@"Double Tap");
	} else {
		[super touchesBegan: touches withEvent: event ];
	}
}
That will override the touch event and if its not 2, it passes to the super (UIWebView). By the way, I believe touchesBegan: withEvent: is only called on the first touch, I think you need to check the touchesEnded: or whatever it's called.

Max
mxweas is offline   Reply With Quote
Old 08-04-2008, 11:54 PM   #8 (permalink)
mdj
New Member
 
Join Date: Aug 2008
Posts: 5
mdj is on a distinguished road
Default Still no go...

It won't work because UIWebView does not respond to touch events.

I've attached a sample project you can see a test of what I'm trying to do. The sample project loads Twitter into a UIWebView (SRWebView) subclass that has the touchesBegan event overridden (even though it wont respond). It also places a UIView subclass (SGTransparentView) on top of the WebView, which does respond to the touchesBegan event, but it does not let me scroll the underlying web view.

Thanks for your responses so far.
Attached Files
File Type: zip WebViewTouch.zip (19.3 KB, 237 views)
mdj is offline   Reply With Quote
Old 09-10-2008, 08:47 AM   #9 (permalink)
New Member
 
Join Date: May 2008
Age: 28
Posts: 65
paos is an unknown quantity at this point
Default

I'm having the same problem but instead of using a webView I'm using a textView, did somebody find out how to solve this??
paos is offline   Reply With Quote
Old 11-16-2008, 06:49 PM   #10 (permalink)
Registered Member
 
brendand's Avatar
 
Join Date: Aug 2008
Posts: 223
brendand is on a distinguished road
Default

Was there any resolution to this problem? I'm also having this issue. I'm trying to detect a user's tap so I can toggle the navigation bar and tab bar in my application. I know lots of applications are doing this, but I don't know how they're doing it. Any ideas? I've tried overlaying a custom UIView to detect the tap. This works, but it doesn't pass the taps on to the UIWebview underneath. I've tried a bunch of different ways of passing the message, including passing on to the next responder, the super view's first child (which is my UIWebView), but nothing seems to happen.

In fact, when I comment out my touchesBegan method, it should just pass the touches onto UIWebView underneath my invisible UIView, but it doesn't.

Thanks.
brendand is offline   Reply With Quote
Old 02-15-2009, 07:32 AM   #11 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 3
mhaseebkhan is on a distinguished road
Default Same Issue

Hi All,

I am working on an application and implement swipe on the UIWebView.

I am still not able to find anything.

Please let me know if anyone has figured out a solution to this.

Thanks and Regards,

Muhammad Haseeb Khan
mhaseebkhan@gmail.com
TkXel
mhaseebkhan is offline   Reply With Quote
Old 11-22-2009, 10:51 PM   #12 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Sanford, FL
Posts: 19
alyanm is on a distinguished road
Default

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];
}

Last edited by alyanm; 11-23-2009 at 10:24 AM. Reason: Figured out a solution!
alyanm is offline   Reply With Quote
Old 12-13-2009, 06:08 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 1
Bristo is on a distinguished road
Red face Passing a click to UIWebView from UIView Overlay

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 View Post
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];
}

Last edited by Bristo; 12-13-2009 at 08:30 PM. Reason: Solution provided.
Bristo is offline   Reply With Quote
Old 12-13-2009, 07:20 PM   #14 (permalink)
Banned
 
Join Date: Oct 2009
Location: East Bay, CA
Posts: 171
youngcoder is on a distinguished road
Default this will do it for you

check this out... it will solve your swiping issue....

http://iPhoneIncubator.com/files/iPhoneIncubator.tar.gz

HTH
youngcoder is offline   Reply With Quote
Old 01-03-2010, 03:23 AM   #15 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
ashish_pandita is on a distinguished road
Default How to stop pinch zooming in UIWebView

hi tried iPhoneIncubator.tar.gz
there is a snoop window and you can get notification from that class which you can use in your controller class.

But I dont want my web view to zoom.
How to stop that in snoopWindow class ?
Any help

thanks
ashish
ashish_pandita is offline   Reply With Quote
Old 01-03-2010, 05:23 AM   #16 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 9
ashish_pandita is on a distinguished road
Default

-(UIView *)hitTestCGPoint)point withEventUIEvent *)event {

NSLog(@"hitTest called");
//NSArray *allTouches = [[event allTouches] allObjects];
UITouch *touch = [[event allTouches] member:webView];
NSLog(@"touch %@",[touch description]);

BOOL forwardToSuper = YES;
if (webView)
{
if ([touch tapCount] >= 2) {
//prevent this
forwardToSuper = NO;
NSLog(@" *****web touch*****");

}

}else {
forwardToSuper = YES;
}
if(forwardToSuper)
{
return [super hitTestoint withEvent:event];
}
else {
return self;
}



}

I am getting touch as null in console. Any help?

Last edited by ashish_pandita; 01-03-2010 at 06:52 AM.
ashish_pandita is offline   Reply With Quote
Old 07-07-2010, 09:12 AM   #17 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Sanford, FL
Posts: 19
alyanm is on a distinguished road
Default

Well, I've gotten complaints from users beginning with the release of the iPad and now iOS4 that this no longer works right. I'm wondering if anybody knows how to fix my code? It sounds kinda stupid when I say it that way...

I'm kinda thinking the new UIGestureRecognizer might be the way to go... but it sure would be a lot easier if I could just fix this code for iOS4 compatibility.

Thanks,
Alan
alyanm is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 333
9 members and 324 guests
chiataytuday, coolman, givensur, ipodphone, jbro, mtl_tech_guy, Punkjumper, vilisei, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:14 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0