Get Updates By E-mail 

Article Written By:
Johann Dowa

Swift Library That Uses Protocols To Dramatically Simplify Handling Common Gestures

  •  
  •  
  •  
  •  
  •  

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:

class MyRotatableView : UIView, Rotatable {
    init(frame: CGRect) {
        super.init(frame: frame)
        self.makeRotatable()
    }
}

And to perform actions simply implement the appropriate method:

func didStartRotating()
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.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments