Skip to content

Instantly share code, notes, and snippets.

@paulz
Last active May 31, 2016 19:44
Show Gist options
  • Save paulz/5599bde8e961f5a5eb5dedc9f8ee3e85 to your computer and use it in GitHub Desktop.
Save paulz/5599bde8e961f5a5eb5dedc9f8ee3e85 to your computer and use it in GitHub Desktop.
Three ways to completion blocks in Swift
func startScrolling() {
scrollLimit = Int(contentImageView.bounds.size.width - scrollView.bounds.size.width)
scrollByFraction(.Start)
UIView.animateWithDuration(15,
delay: 0,
options: [.Autoreverse,.Repeat,.BeginFromCurrentState],
animations: {self.scrollByFraction(.End)},
completion: {_ in self.centerContent()})
}
func startScrolling() {
scrollLimit = Int(contentImageView.bounds.size.width - scrollView.bounds.size.width)
scrollByFraction(.Start)
func animations() {
scrollByFraction(.End)
}
func onAnimationComplete(completed:Bool) {
centerContent()
}
UIView.animateWithDuration(15,
delay: 0,
options: [.Autoreverse,.Repeat,.BeginFromCurrentState],
animations: animations,
completion: onAnimationComplete)
}
func scrollToLimit() {
scrollByFraction(.End)
}
func onAnimationComplete(completed:Bool) {
centerContent()
}
func startScrolling() {
scrollLimit = Int(contentImageView.bounds.size.width - scrollView.bounds.size.width)
scrollByFraction(.Start)
UIView.animateWithDuration(15,
delay: 0,
options: [.Autoreverse,.Repeat,.BeginFromCurrentState],
animations: scrollToLimit,
completion: onAnimationComplete)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment