extension UIScrollView {
func scrollPositionY(view:UIView) -> CGFloat {
if let origin = view.superview {
// Get the Y position of your child view
let childStartPoint = origin.convert(view.frame.origin, to: self)
let this = childStartPoint.y
return this
}
}
}
and then
let theYvalue = theScrollView.scrollPositionY
theYvalue is of type (UIView) -> CGFloat
Can I convert this to a CGFloat?
Thank you!
You didn't call the function. Functions are called using
(), and because you have parameters, arguments need to be passed in, like(view: someViewPassedIn)wheresomeViewPassedInmust be of typeUIView.In Swift, the difference between functions and closures is very small. Variables can be set as a closure, which is what
(UIView) -> CGFloatis. It is a closure that has not been called like a function.It can be quite hard to wrap your head around, but basically closures contain the block of code between the curly brackets/braces,
{}, and the()runs that block of code.Instead of:
Try: