Iphone – How to programmatically determine if an “touchUpInside” event occured

cocoa-touchiphoneuikit

It seems like if this method will be called any time the user touches my view:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if ([touch view] == self && [touch tapCount] >= 1) {
        // do something...
    }
}

I've implemented this in an UIScrollView. The documentation for UIEvent doesn't mention those touchUpInside, touchUpOutside, etc. events that are available in Interface Builder when making connections to action methods.

Actually I want a method to be called only upon one of those "touchUpInside" events, rather than on any kind of touch.

Best Answer

You want touchesEnded:withEvent:. The touchesBegan method gets called when a touch or series of touches starts within a UIResponder; the touchesEnded method gets called when that batch of touches is done (i.e. your user stops touching the screen/lifts a finger).

Related Topic