         self.initializeSlidingNavbar()
     }
 
-    public func setAnchor(offsetY: CGFloat) {
+    open func setAnchor(offsetY: CGFloat) {
         self.anchorOffsetY = offsetY
         self.anchorView = nil
     }
 
-    public func setAnchor(view: UIView) {
+    open func setAnchor(view: UIView) {
         self.anchorView = view
         self.anchorOffsetY = nil
     }
 
-    private func initializeSlidingNavbar() {
+    open func initializeSlidingNavbar() {
         self.navigationBar.clipsToBounds = true
         self.navigationItem.titleView = self.navigationBarView
         self.navigationBarView.isHidden = true
     }
 
-    public func didScroll(offset: CGFloat, convertView: UIView) {
-        var anchorOffset: CGFloat = 0
-
-        if let anchorView = self.anchorView {
-            var frame = anchorView.convert(anchorView.frame.origin, to: convertView)
-            frame = CGPoint(x: frame.x, y: frame.y - anchorView.bounds.height)
-
-            anchorOffset = frame.y
-        } else if let anchorOffsetY = self.anchorOffsetY {
-            anchorOffset = anchorOffsetY
-        }
+    open func didScroll(offset: CGFloat, convertView: UIView) {
+        let anchorOffset: CGFloat = self.getAnchorOffset(convertView: convertView)
 
         let offsetY = min(self.navigationBarView.frame.height + self.navigationBar.frame.height, max(0, offset - anchorOffset))
 

            )
        )

        if offsetY > 0 {
            self.navigationBarView.isHidden = false
        } else {
            self.navigationBarView.isHidden = true
        }
    }
}


import UIKit

open class ALSlidingNavigationBar {
    var navigationBar: UINavigationBar!
    var navigationBarView: UIView!
    var navigationItem: UINavigationItem!

    open var anchorView: UIView?
    open var anchorOffsetY: CGFloat?

    public init(navigationBar: UINavigationBar, navigationItem: UINavigationItem, navigationBarView: UIView) {
        self.navigationBarView = navigationBarView
