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 05-09-2011, 10:21 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 54
amatoria is on a distinguished road
Default Move UIPopoverController under the finger

All I want is to move the UIPopover view under the finger as it moves along the screen. But, that should only happen when I tap on top bar (navigation) and move the finger.

Problem I am facing with attached sample project (~20 KB size) is..
1. Popover is moving fine as I move window in horizontal direction but has issue when this movement is vertical or combined with vertical direction. Vertical direction movement is delayed till my finger crosses half past the popover view. (Note: my popover view is at the top of window in start and I tap & move finger at top bar of popover)
2. Popover moves when I tap and move the finger anywhere in UIPopover, not just the top bar.
...

Below code, ABPopViewController is inherited from UIViewController, nothing in it as of now.

Code snippet related to popover creating and gesture handling is..

Code:
- (IBAction)tapAction:(id)sender {

	if (ABPopoverVC == nil) {
		// View controller to come up in popover.
		ABPopViewController *popViewController = [[ABPopViewController alloc]
									initWithNibName:@"ABPopViewController" bundle:nil];
		// TODO - Need to check if we really require navigation controller. Normal bar could do.
		UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:popViewController];
		
		// Add gesture to make the view move along with finger.
		UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc]
													   initWithTarget:self action:@selector(handlePanGesture:)];
		
		[navController.view addGestureRecognizer:gestureRecognizer];
		[gestureRecognizer release];
	
		popViewController.title = @"My title";

		// Initialize the popover controller with nav controller
		ABPopoverVC = [[UIPopoverController alloc] initWithContentViewController:navController];
		// Don't let it dismiss, unless explicit close.
		ABPopoverVC.passthroughViews = [NSArray arrayWithObject:self.view];
		rectPopover = tapMeButton.frame;	// Rect to present the popover.

		[navController release];
		[popViewController release];
	}

	// Present the popover.
	[ABPopoverVC presentPopoverFromRect:rectPopover inView:self.view
			   permittedArrowDirections:0 animated:YES];	// Would Apple accept this? How does other floats a view controller then?
}

- (void) handlePanGesture:(UIGestureRecognizer*)gestureRecognizer {
	NSAssert([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]], @"Came across unexpected gesture");

	UIPanGestureRecognizer *gestureRecog = (UIPanGestureRecognizer *)gestureRecognizer;	// Remove compile warning.
	
	if ([gestureRecognizer state] == UIGestureRecognizerStateChanged || [gestureRecognizer state] == UIGestureRecognizerStateBegan) {
		// Translation delta to track the movement of finger.
		CGPoint translationPoint = [gestureRecog translationInView:[gestureRecog.view superview]];
		NSLog(@"translationPoint = %f %f", translationPoint.x, translationPoint.y);

		// Update the popover location.
		rectPopover.origin.x += translationPoint.x;
		rectPopover.origin.y += translationPoint.y;
		NSLog(@"newPositionRect = %f %f", rectPopover.origin.x, rectPopover.origin.y);
		// ??? - Why do we need to set the translation? If we don't set it, nav bar gets behind the view.
		[gestureRecog setTranslation:CGPointZero inView:[gestureRecog.view superview]];

		// Present the popover at updated location.
		[ABPopoverVC presentPopoverFromRect:rectPopover inView:self.view permittedArrowDirections:0 animated:NO];
	}
}
Kindly help. Many thanks.
Attached Files
File Type: zip PushWallView.zip (26.0 KB, 36 views)
amatoria is offline   Reply With Quote
Old 05-10-2011, 01:31 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 54
amatoria is on a distinguished road
Default

I have lots of expectation from this forum. Please help.
amatoria is offline   Reply With Quote
Old 06-30-2011, 02:21 PM   #3 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
cduck is on a distinguished road
Default Re: Move UIPopoverController under the finger

Quote:
Originally Posted by amatoria View Post
2. Popover moves when I tap and move the finger anywhere in UIPopover, not just the top bar.
This is because you add the gesture recognizer to the entire navigation controller view. Use navController.navigationBar instead of navController.view to specify only the navigation bar.

Replace the following
Code:
[navController.view addGestureRecognizer:gestureRecognizer];
with
Code:
[navController.navigationBar addGestureRecognizer:gestureRecognizer];
cduck is offline   Reply With Quote
Reply

Bookmarks

Tags
uinavigationcontroller, uipangesturerecognizer, uipopovercontroller

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: 345
8 members and 337 guests
iOS.Lover, lorrettaui53, MikaelBartlett, oztemel, pbart, PlutoPrime, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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