Last active
May 31, 2016 19:44
-
-
Save paulz/5599bde8e961f5a5eb5dedc9f8ee3e85 to your computer and use it in GitHub Desktop.
Three ways to completion blocks in Swift
This file contains 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
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()}) | |
} |
This file contains 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
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) | |
} |
This file contains 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
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