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-03-2010, 05:41 PM   #1 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default Touch Problem

I'm having some touch problems. I'm trying to make it where if you touch one of these labels, it will fire up the typing method. I'm trying it with just the first label, but no matter where I touch(even if I don't touch any other labels), the program thinks I'm only touching the first label. Can anyone help me? Here's the code:


Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch = [[event allTouches] anyObject]; //maybe this
	CGRect touchFrame = touch.view.frame;
	if (CGRectIntersectsRect(touchFrame, textOne.frame))
	{
		output.text = @"";
		i = 0;
		timer = [NSTimer scheduledTimerWithTimeInterval:.05
									   target:self 
									 selector:@selector(typing:) 
									 userInfo:nil 
									  repeats:YES];
	}
}
__________________
iisword is offline   Reply With Quote
Old 12-03-2010, 09:25 PM   #2 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Anyone?
__________________
iisword is offline   Reply With Quote
Old 12-04-2010, 07:34 AM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Code:
CGRect touchFrame = touch.view.frame;
if (CGRectIntersectsRect(touchFrame, textOne.frame)){
   //stuff
}
Calling touch.view gives you the view that was touched, and touch.view.frame is its frame. If you touch the background of your screen then that frame might be the entire screen; and the entire screen always intersects every view on the screen.

I'd log touch.view and touchFrame to see what's really happening, but you probably want to check if touch.view == textOne or [touch.view isDescendantOfView:textOne] in order to see it textOne was touched.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 12-04-2010, 01:11 PM   #4 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Alright so I did what you asked and I found out that I was clicking the background with this statement:

Code:
if (touch.view == textOne)
	{
		output.text = @"";
		i = 0;
		timer = [NSTimer scheduledTimerWithTimeInterval:.05
									   target:self 
									 selector:@selector(typing:) 
									 userInfo:nil 
									  repeats:YES];
	}
	if (touch.view == self.view) NSLog(@"Failed");
I also tried to touch the label to see if I could get it to run the first if statement, but that failed. So my question now becomes how do I get touch to realize it's touching the label.
__________________
iisword is offline   Reply With Quote
Old 12-04-2010, 02:47 PM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

What did you see when you log touch.view? What view (if any) is getting the touch when you click the textarea?
__________________

Free Games!
smasher is offline   Reply With Quote
Old 12-05-2010, 01:09 AM   #6 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
What did you see when you log touch.view? What view (if any) is getting the touch when you click the textarea?
I'm seeing this this from the code
Code:
if (touch.view == self.view) NSLog(@"Failed");
The self.view I believe is the background.
__________________
iisword is offline   Reply With Quote
Old 12-05-2010, 10:26 AM   #7 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Sorry, I'm not being clear. You need to log the view and find out what view is being touched; then you can figure out what condition to write.

Code:
NSLog(@"touch.view: %@", touch.view);
NSLog(@"self.view: %@", self.view);
NSLog(@"textOne: %@", textOne);

NSLog(@"self.view: %d", [touch.view isDescendantOfView:textOne]);
__________________

Free Games!
smasher is offline   Reply With Quote
Old 12-05-2010, 08:05 PM   #8 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

Thanks for being clearer. Here are the results:

Code:
2010-12-05 21:04:02.749 TextBoxExample[9484:207] touch.view: <UIView: 0x4e05160; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x4e04fb0>>
2010-12-05 21:04:02.750 TextBoxExample[9484:207] self.view: <UIView: 0x4e05160; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x4e04fb0>>
2010-12-05 21:04:02.750 TextBoxExample[9484:207] textOne: <UILabel: 0x4e05b60; frame = (52 100; 49 21); text = 'Text 1'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x4e050b0>>
2010-12-05 21:04:02.751 TextBoxExample[9484:207] self.view: 0
__________________

Last edited by iisword; 12-05-2010 at 08:08 PM.
iisword is offline   Reply With Quote
Old 12-05-2010, 08:21 PM   #9 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Try getting the location of the touch, and checking if CGRectContainsPoint(textOne.frame, touchLocation). That should tell you if the touch point was inside the textOne frame.
__________________

Free Games!
smasher 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: 365
6 members and 359 guests
chemistry, daudrizek, HemiMG, Kirkout, MarkC
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:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0