Wednesday, June 5, 2013

UIScrollView touchesShouldBegin example in Objective C (iOS).


UIScrollView touchesShouldBegin

Overridden by subclasses to customize the default behavior when a finger touches down in displayed content.

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view

Parameters
touches
A set of UITouch instances that represent the touches for the starting phase of the event represented by event.
event
An object representing the event to which the touch objects in touches belong.
view
The subview in the content where the touch-down gesture occurred.

Return Value of [UIScrollView touchesShouldBegin]
Return NO if you don’t want the scroll view to send event messages to view. If you want view to receive those messages, return YES (the default).

Discussion of [UIScrollView touchesShouldBegin]
The default behavior of UIScrollView is to invoke the UIResponder event-handling methods of the target subview that the touches occur in.

UIScrollView touchesShouldBegin example.
- (BOOL) touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
    if ([touches count] == 2) {
        return YES;
    }
    else {
        return NO;
    }
}

Example of [UIScrollView touchesShouldBegin].
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
id  element;
NSEnumerator *setEnum =   [touches objectEnumerator];

while ((element = [setEnum nextObject]) != nil)
{
    NSLog(@"element:%@", element);   
}

return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}

UIScrollView touchesShouldBegin example.
/*
 The default behavior of UIScrollView is to invoke
 the UIResponder event-handling methods of the target subview that the touches occur in.
 */
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
BOOL ret;
ret = [super touchesShouldBegin:touches withEvent:event inContentView:view];

#if TRACE_TOUCH_ENABLE
if(ret)
NSLog(@"SwTextView touchesShouldBegin,return YES");
else
NSLog(@"SwTextView touchesShouldBegin,return NO");
#endif

return ret;
}

End of UIScrollView touchesShouldBegin example article.