Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After pulling to refresh, a line appears under the Navigation bar #23

Closed
fraserscottmorrison opened this issue Jan 28, 2016 · 5 comments

Comments

@fraserscottmorrison
Copy link

After pulling to refresh, a line appears under the Navigation bar until refresh has finished. Can you point our where in the library this might be occurring?

Im setting an image as the background self.navigationController!.navigationBar.setBackgroundImage(...)
And hiding the shadow with this self.navigationController!.navigationBar.shadowImage = UIImage()

pulling

loading

@gontovnik
Copy link
Owner

Really weird. Please look into my implementation of that in the example project. I have exactly the same case when navigation bar and wave are the same colour and I did not have any line appearing.

I am closing this ticket.

Please feel free to re-open if you cannot fix it by implementing it the same way as I did.

@fraserscottmorrison
Copy link
Author

It looks like its because Im using a transparent navBar and transparent refreshView

Ive modified your implementation to be transparent and get the same issue. Heres the changes Ive made:

    class ViewController: UIViewController {
            override func loadView() {
                    super.loadView()

                    navigationController?.navigationBar.translucent = false
                    navigationController?.navigationBar.setBackgroundImage(self.imageWithColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0)), forBarMetrics: .Default)
                    navigationController?.navigationBar.shadowImage = UIImage()
                    navigationController?.navigationBar.barTintColor = UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0)
                    // .....
                    tableView.dg_setPullToRefreshFillColor(self.getAdjustedTransparencyColor(UIColor(red: 57/255.0, green: 67/255.0, blue: 89/255.0, alpha: 1.0), alpha: 0.915))
                    // .....
            }

        func imageWithColor(color: UIColor) -> UIImage {
            let rect: CGRect = CGRectMake(0.0, 0.0, 1.0, 1.0)
            UIGraphicsBeginImageContext(rect.size)
            let context: CGContextRef = UIGraphicsGetCurrentContext()!
            CGContextSetFillColorWithColor(context, color.CGColor)
            CGContextFillRect(context, rect)
            let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return image
        }

        func getAdjustedTransparencyColor(navBarColor: UIColor?, alpha: CGFloat) -> UIColor {
            var red:CGFloat = 0
            var green:CGFloat = 0
            var blue:CGFloat = 0
            var alphaX:CGFloat = 0
            navBarColor?.getRed(&red, green: &green, blue: &blue, alpha: &alphaX)

            var opacity:CGFloat = 1

            let minVal: CGFloat = min(min(red, green), blue)
            if self.convertValue(minVal, withOpacity: opacity) < 0 {
                opacity = self.minOpacityForValue(minVal)
            }

            red = self.convertValue(red, withOpacity: opacity)
            green = self.convertValue(green, withOpacity: opacity)
            blue = self.convertValue(blue, withOpacity: opacity)

            red = max(min(1.0, red), 0)
            green = max(min(1.0, green), 0)
            blue = max(min(1.0, blue), 0)

            return UIColor(red: red, green: green, blue: blue, alpha: alpha)
        }

        func convertValue(value: CGFloat, withOpacity opacity: CGFloat) -> CGFloat {
            return 0.4 * value / opacity + 0.6 * value - 0.4 / opacity + 0.4
        }

        func minOpacityForValue(value: CGFloat) -> CGFloat {
            return (0.4 - 0.4 * value) / (0.6 * value + 0.4)
        }
    }

But I still can't see whats causing the line to appear

@fraserscottmorrison
Copy link
Author

Ah so its happening because Ive set them to transparent and sometimes they overlay which causes the darker line.

If I modify DGElasticPullToRefreshView a little and put in a 1point buffer then the line doest appear, but worse theres sometimes a 1point white gap sigh

Any idea how I can fix this?

private func currentPath() -> CGPath {
    let width: CGFloat = scrollView()?.bounds.width ?? 0.0

    let bezierPath = UIBezierPath()
    let animating = isAnimating()
    var buffer:CGFloat = 0.0
    if animating {
        buffer = 1.0
    }

    bezierPath.moveToPoint(CGPoint(x: 0.0, y: buffer))
    bezierPath.addLineToPoint(CGPoint(x: 0.0, y: l3ControlPointView.dg_center(animating).y))
    bezierPath.addCurveToPoint(l1ControlPointView.dg_center(animating), controlPoint1: l3ControlPointView.dg_center(animating), controlPoint2: l2ControlPointView.dg_center(animating))
    bezierPath.addCurveToPoint(r1ControlPointView.dg_center(animating), controlPoint1: cControlPointView.dg_center(animating), controlPoint2: r1ControlPointView.dg_center(animating))
    bezierPath.addCurveToPoint(r3ControlPointView.dg_center(animating), controlPoint1: r1ControlPointView.dg_center(animating), controlPoint2: r2ControlPointView.dg_center(animating))
    bezierPath.addLineToPoint(CGPoint(x: width, y: buffer))

    bezierPath.closePath()

    return bezierPath.CGPath
}

@fraserscottmorrison
Copy link
Author

By the way the reason I want your refreshView transparent it because I have a parallax image which, when you pull, is visible under your refreshView. Looks really cool
parallax

@andrealufino
Copy link

andrealufino commented Aug 25, 2016

Did you figure out how to do it? I mean how to create that cool effect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants