Created
August 7, 2017 06:16
-
-
Save johneris/9c574196e6456bd11f75dd956fe3bffc to your computer and use it in GitHub Desktop.
iOS UIView Extension - Get the frame of view relative to the desired superview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func frameRelative(to targetSuperView: UIView) -> CGRect { | |
var view = self | |
var rect = view.frame | |
while let sv = view.superview { | |
if sv == targetSuperView { | |
return rect | |
} | |
rect = view.convert(rect, to: sv) | |
view = sv | |
} | |
return rect | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment