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 12-16-2010, 11:00 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 14
risma is on a distinguished road
Default touchesBegan and touchesEnded detected on another subview

hi i really got stuck in a week about this case. i have a UIBarButtonItem inside UINavigationItem, the hierarchy is like this

UIViewController
|
myViewController
|
view-> UIToolbar -> UIBarbuttonItem

->UINavigationBar -> UINavigationItem->UISegmentedControl -> UIBarButtonItem

The UIBarbuttonitem and UIsegmentedControl below UINavigationItem are made programmatically, but the others are made in IB. The BarButtonItem is a wrapper of segmentedControl.

in this case, i want to show a view after pressing or touching the barbuttonitem. In several thread i read in this forum, i knew that UIBarbuttonItem didn't inherit UIResponder, so i choose the NavigationBar to get the touch, and i define a frame for it.

this is the code i made :

Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	int indexSegment = _docSegmentedControl.selectedSegmentIndex;
	NSLog(@"index di touches began : %d", index);
	CGFloat x;
	
	if (indexSegment == 0) {
		x = 0.0;
	}else if (indexSegment == 1) {
		x = widthSegment + 1;
	}else if (indexSegment == 2) {
		x = 2*widthSegment + 1;
	}else if (indexSegment == 3) {
		x = 3*widthSegment+ 1;
	}else if (indexSegment == 4) {
		x = 4*widthSegment + 1;
	}
	
	CGRect frame = CGRectMake(x, 0.00, widthSegment, 46.00);
	
	UITouch *touch = [[event allTouches] anyObject];
	
	CGPoint gestureStartPoint = [touch locationInView:[self navBar]];
	[navBar becomeFirstResponder];
	NSLog(@"gesturestart : %f, %f", gestureStartPoint.x, gestureStartPoint.y);	
	NSLog(@"frame : %f, %f, %f, %f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
	
	if (CGRectContainsPoint(frame, gestureStartPoint)) {
		NSLog(@"begin");
		[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(segmentItemTapped:) object:[self navBar]];
	}
}
the navBar was declare in myViewController.h and i set it as an IBOutlet.

Code:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
	int indexSegment = _docSegmentedControl.selectedSegmentIndex;
	NSLog(@"index di touches ended : %d", index);
	
	CGFloat x;
	
	if (indexSegment == 0) {
		x = 0.0;
	}else if (indexSegment == 1) {
		x = widthSegment + 1;
	}else if (indexSegment == 2) {
		x = 2*widthSegment + 1;
	}else if (indexSegment == 3) {
		x = 3*widthSegment+ 1;
	}else if (indexSegment == 4) {
		x = 4*widthSegment + 1;
	}
	
	CGRect frame = CGRectMake(x, 0.00, widthSegment, 46.00);
	NSLog(@"frame ended : %f, %f, %f, %f", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
	
	UITouch *touch = [[event allTouches] anyObject];
	
	CGPoint gestureEndPoint = [touch locationInView:[self navBar]];
	[navBar becomeFirstResponder];
	
	NSLog(@"lastPOint : %f, %f", gestureEndPoint.x, gestureEndPoint.y);
	
	if (CGRectContainsPoint(frame, gestureEndPoint)) {
		NSLog(@"inside");
		if (touch.tapCount <= 2) {
			[self performSelector:@selector(segmentItemTapped:) withObject:[self navBar] afterDelay:0.35];
			//[navBar performSelector:@selector(segmentItemTapped:) withObject:segmentItem afterDelay:0.35];
			NSLog(@"masuk g??");
		}
	}
	
	
}
touchesBegan and touchesEnded was detected when i tap at the toolbar, NOT in the navbar.

i did implemented the hitTest method like this :

Code:
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
	UIView *touchedView = [navBar hitTest:point withEvent:event];
	NSSet *touches = [touches anyObject];
	
	return touchedView;
}

but it still nothing get better.

Somebody can decribe why this is happen? Regards
-Risma-

Last edited by risma; 12-17-2010 at 12:46 AM.
risma is offline   Reply With Quote
Reply

Bookmarks

Tags
uibarbuttoitem, uinavigationbar, uinavigationcontroller, uitoolbar

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: 393
9 members and 384 guests
chemistry, daudrizek, HemiMG, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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