Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollview delaysContentTouches issue

I have UIScrollView loaded with UIButtons and on UIButton action I have highlighted UIImage of each UIButton.

If I don't set delaysContentTouches as NO then highlighted UIImage of UIButton will not shown if I touch up UIButton very fast. After I set delaysContentTouches property as NO then only UIButton highlighted UIImage is shown.

Now after setting delaysContentTouches property as NO for UIScrollView. I can not scroll my UIScrollView by dragging on the UIButtons. Now how can I resolve this issue.

Please give me an advise.

Thanks in advance.

like image 667
Piyush Hirpara Avatar asked Jul 17 '13 13:07

Piyush Hirpara


3 Answers

Here's what works for me. Subclass UIScrollView, and implement only this method:

- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
    return YES;
}

Then set delaysContentTouches = NO;

Voila! Works just like the home screen: Highlights buttons immediately, but still allows scrolling :)

like image 193
Chris Avatar answered Nov 19 '22 16:11

Chris


I found that in iOS 8, the UIScrollView's underlying UIPanGestureRecognizer is not respecting the UIScrollView's delaysContentTouches property. I consider this an iOS 8 bug. Here's my workaround:

theScrollView.panGestureRecognizer.delaysTouchesBegan = theScrollView.delaysContentTouches
like image 36
lifjoy Avatar answered Nov 19 '22 17:11

lifjoy


OK I have resolved by implementing below method :

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
    NSLog(@"touchesShouldCancelInContentView");

    if ([view isKindOfClass:[UIButton class]])
        return NO;
    else
        return YES;
}
like image 8
Piyush Hirpara Avatar answered Nov 19 '22 17:11

Piyush Hirpara