Demo entry 6634784

objective-c

   

Submitted by objective-c on Aug 14, 2017 at 16:39
Language: Objective-C. Code size: 552 Bytes.

//OC 函数实现: 正规版本
static CGFloat rubberBandDistance(CGFloat offset, CGFloat dimension) {
    
    const CGFloat constant = 0.55f;
    CGFloat result = (constant * fabs(offset) * dimension) / (dimension + constant * fabs(offset));
    // The algorithm expects a positive offset, so we have to negate the result if the offset was negative.
    return offset < 0.0f ? -result : result;
}

//最初版本:
static CGFloat previousRubberBandDistance(CGFloat offset) {
    CGFloat result = fabs(offset) * 0.5;
    return offset < 0.0f ? -result : result;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).