     - Returns: The top NSLayoutConstraint if found.
      */
     public var topConstraint: NSLayoutConstraint? {
-        return constraintForView(self, attribute: .top)
+        return constraintForView(self, attribute: .top, existsOnView: self.superview)
     }
     
     /** Gets the bottom constraint if found.

     - Returns: The width NSLayoutConstraint if found.
     */
    public var widthConstraint: NSLayoutConstraint? {
        return constraintForView(self, attribute: .width)
    }
    
}

func constraintForView(_ v: UIView, attribute: NSLayoutAttribute) -> NSLayoutConstraint? {
    if let spv = v.superview {
        for c in spv.constraints {
            if let fi = c.firstItem as? NSObject, fi == v && c.firstAttribute == attribute {
                return c
            }
            if let si = c.secondItem as? NSObject, si == v && c.secondAttribute == attribute {
                return c
            }
        }
    }
    return nil

     - Returns: The bottom NSLayoutConstraint if found.
     */
    public var bottomConstraint: NSLayoutConstraint? {
        return constraintForView(self, attribute: .bottom, existsOnView: self.superview)
    }
    
    /** Gets the height constraint if found.
