Mike Simz
Mike Simz

Reputation: 4026

UIScrollView with UIButtons - Scroll View won't scroll when touch began on button

I just updated to xCode 6 and iOS 8 and I noticed something very weird with my app. In my app I have a scrollview with several buttons within it, aligned horizontally. I set it up to create my own custom scrollable tab bar controller. Before the update to iOS 8 and xCode 6 everything was working perfect, but now I realized that when I try to scroll the scrollview left or right, and my initial touch was within one of the buttons in the scroll view, then no scrolling happens. However if I touch in-between the buttons then scrolling works as expected. I think it's some issue where the button is registering the touch and it is as if the scrollview never got touched. But this was 100% working before perfectly so i do not what is going on!!

Upvotes: 2

Views: 2488

Answers (3)

gaurav bhardwaj
gaurav bhardwaj

Reputation: 51

No need to subclass ScrollView Just use this :

yourScrollView.panGestureRecognizer.delaysTouchesBegan =yourScrollView.delaysContentTouches;

Upvotes: 0

Userich
Userich

Reputation: 316

Subclassing UIScrollView and adding code below into .m file, did solve my scrolling freeze problem under iOS 8.

Code:

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
{
    UITouch *touch = [touches anyObject];

    if(touch.phase == UITouchPhaseMoved)
    {
        return NO;
    }
    else
    {
        return [super touchesShouldBegin:touches withEvent:event inContentView:view];
    }
}

This solution was found in pasta12's answer https://stackoverflow.com/a/25900859/3433059

Upvotes: 1

Mike Simz
Mike Simz

Reputation: 4026

I ended up creating a subclass of UIScrollView and set it's cancelContentTouches value to TRUE and my problem was solved

Upvotes: 3

Related Questions