ODRefreshControl icon indicating copy to clipboard operation
ODRefreshControl copied to clipboard

Bounce Area Background / Reduced required pull distance

Open mmackh opened this issue 11 years ago • 4 comments

The background for the bounce area is shown both in Apple's mail and contacts app.

If a project uses both a Navigation & toolbar, the scroll distance of 53 in landscape doesn't work. I've reduced it to 36.

mmackh avatar Jul 28 '12 10:07 mmackh

Regarding the background issue, I don't understand why you don't simply change the refreshControl background color. Doing it your way the color is fixed, and that's not always the case (see the PassBook app).

For the second issue, it's a bit more complicated than that. The scroll distance of 53 is the right one, 36 is too small. The problem is that in the apple application, the tableView gets dragged with less friction, so you can reach the right distance. I'm trying to understand how to do that, I'll post something when I'm done...

Sephiroth87 avatar Jul 28 '12 11:07 Sephiroth87

(gentle ping) - do you have any additional thoughts on how to resolve this yet?

cdzombak avatar Sep 14 '12 03:09 cdzombak

Thoughts have been given, but time has not been found :/

Sephiroth87 avatar Sep 14 '12 08:09 Sephiroth87

This thread looks old, but if folks are still interested in this issue of being able to pull the refreshcontrol when in landscape I've implemented a solution that is working for me. I've applied an acceleration factor to the stretching of the control, so it effectively snaps and pops faster. I'm applying this universally but it would be better to apply different factors in landscape than in portrait (an acceleration factor of 1 will result in existing behavior). The code waits until the pull has exceeded a threshold amount of kOpenedViewHeight, after that it applies an effectiveOffset that uses the acceleration factor to speed up the stretch growth of the control.

I'm not very good with git so I don't know how to offer this via my own commit so I'm pasting in code into this comment.

// define the acceleration factor #define kAccelerateFactor 2.5

// in observeValueForKeyPath replace code that starts at the line: _lastOffset = offset; with:

CGFloat effectiveOffset;
if (offset < -kOpenedViewHeight) {
    // If the scrollview is pulled past the threshold point for stretching then compute an effective offset that is equal to the threshold amount plus
    // (an accelaration factor times the delta offset past the threshold)
    effectiveOffset = -kOpenedViewHeight + ((offset + kOpenedViewHeight) * kAccelerateFactor);
} else {
    effectiveOffset = offset;
}
DDLogVerbose(@"effective offset is %f", effectiveOffset);

_lastOffset = effectiveOffset;

BOOL triggered = NO;

CGMutablePathRef path = CGPathCreateMutable();

//Calculate some useful points and values
CGFloat verticalShift = MAX(0, -((kMaxTopRadius + kMaxBottomRadius + kMaxTopPadding + kMaxBottomPadding) + effectiveOffset));
CGFloat distance = MIN(kMaxDistance, fabs(verticalShift));
CGFloat percentage = 1 - (distance / kMaxDistance);

CGFloat currentTopPadding = lerp(kMinTopPadding, kMaxTopPadding, percentage);
CGFloat currentTopRadius = lerp(kMinTopRadius, kMaxTopRadius, percentage);
CGFloat currentBottomRadius = lerp(kMinBottomRadius, kMaxBottomRadius, percentage);
CGFloat currentBottomPadding =  lerp(kMinBottomPadding, kMaxBottomPadding, percentage);

CGPoint bottomOrigin = CGPointMake(floor(self.bounds.size.width / 2), self.bounds.size.height - currentBottomPadding -currentBottomRadius);
CGPoint topOrigin = CGPointZero;
if (distance == 0) {
    topOrigin = CGPointMake(floor(self.bounds.size.width / 2), bottomOrigin.y);
} else {
    topOrigin = CGPointMake(floor(self.bounds.size.width / 2), self.bounds.size.height + effectiveOffset + currentTopPadding + currentTopRadius);
    if (percentage == 0) {
        bottomOrigin.y -= (fabs(verticalShift) - kMaxDistance);
        triggered = YES;
    }
}

neils4fun avatar Apr 26 '13 00:04 neils4fun