Skip to content

Instantly share code, notes, and snippets.

@MoathOthman
Created October 25, 2015 22:38
Show Gist options
  • Save MoathOthman/b0b8afb51248aad364b6 to your computer and use it in GitHub Desktop.
Save MoathOthman/b0b8afb51248aad364b6 to your computer and use it in GitHub Desktop.
Find x point and y point of a UIView related to the main screen in swift
/** Find the Y point of a view related to the main screen
@pramater UIView the view to start
@return CGFloat the y point to the main screen
*/
func findOutTheYPointToTheScreen(view: UIView) -> CGFloat {
var ypointSummation: CGFloat = view.frame.origin.y
var tView = view
while let v = tView.superview {
ypointSummation += v.frame.origin.y
tView = tView.superview!
}
return ypointSummation
}
/** Find the Y point of a view related to the main screen
@pramater UIView the view to start
@return CGFloat the y point to the main screen
*/
func findOutTheXPointToTheScreen(view: UIView) -> CGFloat {
var ypointSummation: CGFloat = view.frame.origin.x
var tView = view
while let v = tView.superview {
ypointSummation += v.frame.origin.x
tView = tView.superview!
}
return ypointSummation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment