Reputation:
I have a UIScrollView and I want to trigger a function whenever the content offset is equal to a certain value.
I tried
var defaultOffset: CGPoint = ...
func checkScroll() {
for i = 1; i > 0; i {
if ScrollView.contentOffset.x == defaultOffset.x {
functionToTrigger()
i = 0
}
}
}
but that doesn't work.
Help would be much appreciated!
Upvotes: 1
Views: 68
Reputation: 655
I would you recommend a different approach.
Set this class as the UIScrollViewDelegate
.
Then just use scrollViewDidScroll
method to compute your value, like so:
override func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.x == defaultOffset.x {
functionToTrigger()
}
}
Upvotes: 3