How do you tell what object is being touched in touchesBegan?
Posted
by Flafla2
on Stack Overflow
See other posts from Stack Overflow
or by Flafla2
Published on 2010-04-15T19:53:50Z
Indexed on
2010/04/15
21:13 UTC
Read the original article
Hit count: 414
I know that this is a very commonly asked question, but all of the answers on every website don't work! If you still don't know what I mean, then maybe this line of code will help you understand.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if (touch.view == nextbutton)
[self performSelector:@selector(next)];
if (touch.view == prevbutton)
[self performSelector:@selector(previous)];
if (touch.view == moreoptionsbutton)
[self performSelector:@selector(moresettings)];
}
It doesn't do anything when you touch nextbutton, prevbutton, and more optionsbutton
, which are UIImageViews
by the way. I have also tried using isEqual:
instead of ==
, but that hasn't worked out either. Any suggestions?
© Stack Overflow or respective owner