简体   繁体   中英

Nested UIScrollView won't bounce and does not detect slow swipe gestures when bounce is set to NO

Sorry for the long and self explanatory title, but UIScrollView has raised so many questions that I find it difficult to reach the ones that might help in different situations.

I have nested scrollviews in my iPad app. So far so good, everything has its ups and downs but its quite slick and responsive. My outter scroll view is a paged one, that contains fullscreen or bigger content scrollviews in it. Outter scrollview is horizontal and inner vertical. Like the photo gallery one. I found that when I'm zooming and scrolling the inner scrollview, there's a noticeable delay in detecting slow and long swipe gestures ONLY when the scrollview has been scrolled down to the bottom of the content and bouncing is OFF.

the other thing is that the inner scrollview bouncing property goes YES/NO pseudo-randomly. So, this is the code in the constructor that set the inner scrollviews that are acting up:

    if (UIInterfaceOrientationIsPortrait(forOrientation)) {
        self.minimumZoomScale = 1.0;
        self.maximumZoomScale = 1.0;    
        self.bounces = NO;
        self.alwaysBounceVertical = NO;
        self.scrollEnabled = NO;
    }else if (UIInterfaceOrientationIsLandscape(forOrientation)){
        self.minimumZoomScale = 1.333333f;
        self.maximumZoomScale = 1.333333f;
        self.bounces = YES;
        self.alwaysBounceVertical = YES;
        self.scrollEnabled = YES;
    }

    self.scrollsToTop = NO;
    self.showsVerticalScrollIndicator = YES;
    self.showsHorizontalScrollIndicator = NO;
    self.directionalLockEnabled = YES;
    self.delegate = self;



    self.pagingEnabled = NO;

    self.canCancelContentTouches = NO;
    self.delaysContentTouches = YES;

When the iPad is rotated bouncing will come and go for the scroll view as well and will have a bouncing glitch too.

Is this a bug ? or is it just me that I'm messing it up?

thanks in advance for your time and interest!

UPDATE: I'm nesting two scrollviews that are actually Subclasses of UIScrollView. I'm doing this because I need to override hitTest an other methods as well. I also tried the Better solution described here http://openradar.appspot.com/8045239 and did not get any good results.

I'm answering my own question.

Open radar's bug solution that's posted on the question post, it's not very clean on what to isolate in order to stop the uiscrollview from resizing and cancel bounces

Basically EVERYTHING that can change the view's frame during layoutSubViews has to be done only ONCE by double checking that if the size is equal to the change that's coded in layoutSubviews, then that's not ran more than once.

-(void)layoutSubviews {

///...


if (!self.bounces) {
             self.bounces = YES;
        }
        if(!self.scrollEnabled){
           self.scrollEnabled = YES;
        }
        if (!CGSizeEqualToSize(rect.size, self.contentSize)) {
            self.contentSize = rect.size;
        }
 if (self.zoomScale < MAXIMUM_ZOOM_SCALE ) {

            [self zoomToRect:ZOOM_RECT_MAKE animated:NO];// otherwise this line of code won't do anything at all


        }
}

Nesting scrollviews will always lead to touch-responder issues. I'm assuming that the inner is the primary one—the one users interact with more? In general, you're probably going to have to write some of your own touch responders (at least, that has been my experience, both in code and around SO). Make the vertical scrolling more forgiving, but only detect a narrow range of swipes and drags (near-horizontal lines) for the outer. That way, most of the touch inputs will be sent to the inner view.

As far as the bouncing goes, remove one of the places where you set the property and see what happens.

Which method is this in? Hopefully this code is residing in a UIView subclass…?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM