Standard Template Protocols is an open source Swift library submitted by Chris providing a number of protocols for many common tasks allowing you to dramatically clean up your code.
As stated in the submission:
Too often we find ourselves locked into deep and complicated subclassing trees just to factor out common behavior in our apps. This makes our code inflexible, hard to navigate, and contain too many dependencies. Using protocols for common features allows us to create default behavior that is additive without complicated subclassing.
Standard Template Protocols tries to solve these flaws, starting with common patterns around gesture recognizers.
Included within gesture recognizable are Swift protocols for moving, pinching, rotation, tapping, and force touch.
This snippet from the readme shows how one could make a view rotatable with Standard Template Protocols:
init(frame: CGRect) {
super.init(frame: frame)
self.makeRotatable()
}
}
And to perform actions simply implement the appropriate method:
func didFinishRotating(velocity:CGFloat)
func minimumRotation() -> CGFloat
func maximumRotation() -> CGFloat
func transformWithRotation(rotation:CGFloat, lastRotation:CGFloat, velocity:CGFloat) -> CGAffineTransform
func animateToRotatedTransform(transform:CGAffineTransform)
You can find Standard Template Protocols on Github here.
A nice Swift library that utilizes protocols to simplify many common tasks.
Original article: Swift Library That Uses Protocols To Dramatically Simplify Handling Common Gestures
©2016 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.
Reference source: iOS App Dev Libraries, Controls, Tutorials, Examples and Tools