How can I get the object of an Event in objective-c?
I would like to know which element was under the finger, when the touch event was called. Got this event-method:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {}
I know how to get the object with custom events: for example:
-(void)onThumbnailClicked:(NSNotification *)notification
{
//Image-Class has been instantiated a certain times and I get the touched Image through the notification object...
Image* myObject = [notification object];
}
To illustrate my issue: I instantiate a set of Image-Classes through
开发者_运维知识库Image *myImageView = [[Image alloc] initWithImage:myImage];
in this Image-Class I have touches-began / touches-ended methods. Know I try to figure out which image was under my finger when I touched the screen, to perform a certain Action.
Your question doesn't really make sense. The "element" that "fired" your touch event was your finger. The first element to respond to the touch event is either 1) the one that has the IBAction
that was triggered (in which case the sender
parameter of the method is the element that fired the action), or 2) the object in which you've implemented the touches(Began|Moved|Ended):
method.
精彩评论