Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
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:
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.
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
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.
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.